Is there any standard way or any utility library to read/navigate through serialized (via ObjectOutputStream) object's properties?
The problem I'm trying to solve is to upgrade data which was serialized using ObjectOutputStream (legacy) and stored in database. In my case some internal fields were drastically changed and renamed. I cannot read object back using ObjectInputStream, as values of changed fields would be lost (set to null).
In particular there may be need to upgrade it again in future, so it would be better if I could replace old data stored this way with XML serialization. But the general way to accomplish this task would require to iterate through properties (their names, types and values). I wasn't able to find a standard way to read such metadata from serialized data (for example, jackson library could read JSON as an object or as a map of properties and maps, which you can easily manipulate).
Is there any low-level library to work with data, serialized with ObjectOutputStream? Resulting output looks like it contains information about serialized field names and their types. As a last resort I could sort out the format, but I've thought that someone could have done this already, yet I wasn't able to find any libraries myself.
For example, I had a class
public class TestCase implements Serializable
{
int id;
double doubleValue;
String stringValue;
public TestCase(int id, double doubleValue, String stringValue)
{
this.id = id;
this.doubleValue = doubleValue;
this.stringValue = stringValue;
}
}
which was changed to
public class TestCase implements Serializable
{
ComplexId id;
double doubleValue;
String stringValue;
public TestCase(ComplexId id, double doubleValue, String stringValue)
{
this.id = id;
this.doubleValue = doubleValue;
this.stringValue = stringValue;
}
}
class ComplexId implements Serializable
{
int staticId;
String uuid;
public ComplexId(int staticId, String uuid)
{
this.staticId = staticId;
this.uuid = uuid;
}
}
It is not a problem to upgrade the value itself, I just don't know how to peek it and put back a new one (with a new type) without custom implementation of serialization/deserialization protocol (that's a last resort for me).