Error while deserializing the POJO Object

Team, When I send a Serializable Object from Client to Server; I am getting the following exception. I am using the org.apache.commons.lang3.SerializationUtils serialize/deserialize. Customer is a simple pojo implements serializable. Please help me here. Thanks in advance.

Client Send:

    > RSocket source = RSocketFactory.connect()
            .transport(TcpClientTransport.create("localhost", 9000))
            .start()
            .block();
    source
            .requestResponse(DefaultPayload.create(SerializationUtils.serialize(new Customer("John", "Doe", 23))))
            .subscribe(response -> log.info("Response Received --->" + response.getDataUtf8()));

Server Read:

Customer customer = SerializationUtils.deserialize(payload.getData().array());

Exception thrown at above line; I checked and getting java.nio.DirectByteBuffer object:

java.lang.UnsupportedOperationException
at java.nio.ByteBuffer.array(ByteBuffer.java:994)

Let me know what am I missing here.

Thank You
Karthik

Hello @pckeyan. The problem is ByteBuffer returned by payload.getData() has no backing array. Converting payload data & metadata to byte[] requires copying, e.g. using following code

ByteBuf dataByteBuf = payload.sliceData();
byte[] dataBytes = new byte[dataByteBuf.readableBytes()];
dataByteBuf.getBytes(buf.readerIndex(), dataBytes);

For high performance use cases there is standard RSocket RPC https://github.com/rsocket/rsocket-rpc-java, examples are available at https://github.com/mostroverkhov/rsocket-rpc-java-demo.

Regards,
Maksym

Thank You @mostroverkhov, It worked. Can you please let me know is there anyother way to send the POJO in the backed array?

That would require custom implementation of PayloadDecoder. If the goal is getting data as byte[] while avoid double copying the buffer, you can use ZeroCopyPayloadDecoder and apply above code to get bytes array with single copy (need to release original bytebuf after that). Also Payload.sliceData() returns buffer view with original reader index - useful for reading data multiple times without constantly resetting reader index.

Thank you @mostroverkhov, that helps. Can you please let me know is there a documentation available for me to learn deep as I am planning to implement Client Side Load Balancing using RSocket-java?

Project is largely based on netty, so knowledge about some of its parts is helpful, e.g. https://netty.io/4.1/api/io/netty/buffer/ByteBuf.html and https://netty.io/wiki/reference-counted-objects.html.
rsocket-java documention is area we are planning to improve significantly once getting close to 1.0.0 release. In the meantime this community forum is best place to talk about use cases & get directions about particular APIs.