GitXplorerGitXplorer
v

kryo-different_object_versions_handling

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
6c9129c749974954ceafe8136fba64e54fd8fffe

extended project's description; added conclusions

vventh committed 10 years ago
Unverified
2315192209db5525dcaa8a9f7d7722c4327cc490

incorporated java serialization to see, how much is it tolerant

vventh committed 10 years ago
Unverified
bc0d2f3261846c652ea61ed6ddd723f157f019e4

corrected project's description

vventh committed 10 years ago
Unverified
4d6ca76d42b818deb269febaa144a31b2d078de9

initial version of kryo serialization test

vventh committed 10 years ago
Unverified
a6366bdf1f41daa1b90dca0ef35c9a41857773d9

Initial commit

vventh committed 10 years ago

README

The README file for this repository.

kryo different object versions handling

The goal is to check, how kryo and java handles deserialization to a different version of class of an object. I've checked java serialization to see how much java serialization is tolerant.

Kryo Scenarios

  1. object deserialized to new version of class sets new fields to null
  2. deserialization to new class version sets old fields
  3. deserialization object of new class to the object of old class sets only old fields

The scenarios are supported by: KryoSerializationObjectWithDifferentVersionsTest

Java Scenarios

  1. object deserialized to new version of class sets new fields to null
  2. deserialization to new class version sets old fields
  3. deserialization to class version with missing fields sets only existing fields
  4. cannot deserialize to class version with different field type
  5. deserialization object of new class to the object of old class sets only old fields
  6. deserialization object of class with additional field to the object of the old class with different field sequence sets only old fields

The scenarios are supported by: JavaSerializationTest

Model classes

  • Base model (first version)
    
    public class VersionedModel implements Serializable {
        private static final long serialVersionUID = 8492539216375372328L;
        public String firstStringField;
        public int firstPrimitiveField;
    }
    
  • Model with additional fields (there are kryo annotations there, not relevant in java scenarios)
    public class VersionedModel implements Serializable {
    
        private static final long serialVersionUID = 8492539216375372328L;
    
        public String firstStringField;
        public int firstPrimitiveField;
    
        @FieldSerializer.Optional("secondStringField")
        public String secondStringField;
        @FieldSerializer.Optional("secondPrimitiveField")
        public int secondPrimitiveField;
    }
  • Model with a missing field firstStringField
    public class VersionedModel implements Serializable {
        private static final long serialVersionUID = 8492539216375372328L;
        public int firstPrimitiveField;
    }
  • The model has firstPrimitiveField type changed to float (this shall have a different serail version uuid, but I kept the same by purpose)
    public class VersionedModel implements Serializable {
        private static final long serialVersionUID = 8492539216375372328L;
    
        public String firstStringField;
        public float firstPrimitiveField;
    }
  • The model with switched field sequence int field is at the begging now
    public class VersionedModel implements Serializable {
        private static final long serialVersionUID = 8492539216375372328L;
        public int firstPrimitiveField;
        public String firstStringField;
    }
    

Tests launch

Tests can be launched by: mvn clean package

The libraries containing model class must be created. They are copied by maven dependency plugin to the test classpath. Thanks to their location, they're loaded by tests and used to instantiate multiple different model classes at the same time.

Conclusions

  • Kryo serialization is tolerant and needs fields to be additionally annotated, not metioning kryo class registry
  • Java serialization is tolerant, if the serial version uuid number is managed manually
    • the number has to be changed only, if any of serialized fields is changed its type or the serial version id may be left untouched, if there will be a special implementation of deserialization. Either way, this situation must be somehow solved
    • other cases:
      • missing fields,
      • additional fields,
      • different fields sequence isn't relevant from serialization / deserialization point of view, but it's important during service handling