Deserialize a transient field with kryoserialization
Hi All,
I am using kryoserialization with memcached session manager
I have a class which has a transient field , a Map with list of same class and LinkedHashMap.
Serialization works fine but when I deserialize the transient field in null. I want to initialise this field.
This worked perfectly fine when i use default Java Serialization with memcached session manager as I added readObject method to my class which gets called on deserialization and I initialise the transient field.
But I am unable to do this with Kryo Serialization.
I decided to implement KryoSerializable as shown below.(Its sample code similar to my original class)
My transient field gets initialized by the read method but map1 and map2 dont serialise correctly so when deserialization happens map1 and map2 are empty.
Class MyClass implements KryoSerializable{
protected Map<String, List<MyClass>> map1;
protected Map<String,String> map2 = new LinkedHashMap<String, String>();
private transient Manager manager;
@Override
public void read(Kryo kryo, Input input) {
// Initialize transient manager
manager = (Manager) SomeUtilities.get(Manager.class);
}
@Override
public void write(Kryo kryo, Output output) {
// I do nothing here
}
}
Can you please help me solving above issue
Thanks