Home > Blockchain >  How to de-serialize byte[] to Java POJO(or Object) at client side, i.e how will client get the class
How to de-serialize byte[] to Java POJO(or Object) at client side, i.e how will client get the class

Time:06-17

I have two related questions:

  1. I'm able to send byte[] over the network for this class:
class Employee{
    byte[] avroBytes,
    String name
}

In my test case, using MockMvc, I'm able to de-serialize it, and then cast it to Employee object because my test case can use the same POJO from code. However the client will not have this POJO or class information. After it receives the bytes, how can it reconstruct this POJO(or whatever is the equivalent in other languages) or Object? Do I need to send in some class information in the header? It's possible that the client is using Python or some other language, so I need a way for this class information to be generic.

Additional information to comments:

I serialized it using org.springframework.util.SerializationUtils serialize() method

CodePudding user response:

If you need POJO on the client side, you need to share generated code that the schema produce. If you don't need POJO you can populate GenericRecord directly with the schema.

CodePudding user response:

  • if "sending byte[]" isn't necessary, just send data in format of JSON / XML / any-random-middle-format
    • String is just an another kind of byte[]
  • Related