I need to print the content of a serialized Java object (e.g. a java.io.Serializable POJO retrieved from cache) without knowing its class a priori.
Being more specific, I do NOT need to instantiate a new object using the classic ObjectInputStream, I just need to obtain a simple human-readable representation (preferrably JSON) of the object without loading its class in the classpath.
In other words, I need to convert a byte[] (the raw serialized object) to a JSON string without reimplementing ObjectInputStream.
The ObjectInputStream class contains readObject() method for deserializing an object.
For serializing the object, we call the writeObject() method of ObjectOutputStream class, and for deserialization we call the readObject() method of ObjectInputStream class. We must have to implement the Serializable interface for serializing the object.
Python refers to serialization and deserialization by terms pickling and unpickling respectively. The 'pickle' module bundled with Python's standard library defines functions for serialization (dump() and dumps()) and deserialization (load() and loads()).
Deserialization is the process of reconstructing a data structure or object from a series of bytes or a string in order to instantiate the object for consumption. This is the reverse process of serialization, i.e., converting a data structure or object into a series of bytes for storage or transmission across devices.
This one seems promising: https://github.com/unsynchronized/jdeserialize I haven't tried it though.
It is a full implementation of the Object Serialization Stream Protocol, as described in the Java Object Serialization Specification, chapter 6. It does not instantiate any classes described in the stream; instead, it builds up an intermediate representation of the types, instances, and values. Because of this, it can analyze streams without access to the class code that generated them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With