Deserialize a transient member of an object to a non-null default use Kryo

时间:2017-12-18 07:35:50

标签: java serialization kryo

LOAD DATA
INTO TABLE EMP
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS 
(
    "T1" INTEGER ,
    "T2" CHAR,  
    desc_skip FILLER POSITION(1),
    "T3" CHAR,
    "T4" CHAR,
    "T5" INTEGER
)

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 public class MyObj implements Serializable { private transient Map<String, Object> myHash = new HashMap<String, Object>(); ... } in kryo.

2 个答案:

答案 0 :(得分: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..

答案 1 :(得分:0)

您可以简单地使用扩展可序列化的外部化接口并覆盖其writeExternal()方法。

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);

          }

}