Nov11 / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Transient member inside no-arg constructor Class deserialize #80

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.ClassNoConstruct obj=new ClassNoConstruct(10);

2.kryo.writeClassAndObject(output, obj);
3.kryo.setInstantiatorStrategy(new SerializingInstantiatorStrategy());
kryo.readClassAndObject(input);

What is the expected output? What do you see instead?
The transient member x inside does not use default value("abc") as expected.

What version of the Kryo are you using?
2.18

Please provide any additional information below.

public class ClassNoConstruct implements Serializable{
    private transient Object x =new String("abc");
        private int i;
    public ClassNoConstruct(int i){
        this .i=i;
    }
}

Original issue reported on code.google.com by rawl...@gmail.com on 20 Jul 2012 at 11:15

GoogleCodeExporter commented 8 years ago
This is the unfortunate part about using an extralinguistic object creation 
mechanism. It creates an object without running the constructor or initializer. 
Classes must be designed for use in this way. Better is to use the normal 
mechanism and write serializers when appropriate.

Original comment by nathan.s...@gmail.com on 18 Aug 2012 at 3:00