Q#1> how to get Bytes of any object?
The best way to do it is to use ApacheUtils:
To Serialize:
byte[] data = SerializationUtils.serialize(yourObject);
deserialize:
YourObject yourObject = (YourObject) SerializationUtils.deserialize(byte[] data)
---------------
private byte[] convertToBytes(Object object) throws IOException {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos)) {
out.writeObject(object);
return bos.toByteArray();
}
}
And the other way around:
private Object convertFromBytes(byte[] bytes) throws IOException, ClassNotFoundException {
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInput in = new ObjectInputStream(bis)) {
return in.readObject();
}
}