1
public class MyObj implements Serializable {
    private transient Map<String, Object> myHash = new HashMap<String, Object>();
    ...
}

I find this question

Deserialize a transient member of an object to a non-null default in Java

but use standard deserialize in java, it works. but it seems not invoke readObject in kryo.

temp0706
  • 49
  • 6

2 Answers2

0

When you will call objectInputStream.readObject(); while reading your saved object (from file) MyObj's readObject() will be called (if there).

You don't need to call that method (MyObj's readObject()) explicitly on MyObj's object..

DhaRmvEEr siNgh
  • 1,918
  • 2
  • 13
  • 17
  • I understand no need to call that method, but if kryo won't call that method like java standard deserialization, it'll have no chance to gurantee transient object is not null – temp0706 Dec 18 '17 at 14:25
0

You can simply use externalizable interface that extends serializable and override its writeExternal() method.

Class abc implements Externalizable
  {
    transient String name;
    private int age;

    public abc(){ }
    public void writeExternal(ObjectOutput out)       throws IOException
    {
 out.writeObject(name);
 out.writeInt(age);

         }
     public void readExternal(ObjectInput in) throws   IOException,ClassNotFoundException
    { 
 name=(String)in.readObject(name);
 age=(in.readInt(age);

          }

}