Class JacksonMigration


  • public abstract class JacksonMigration
    extends java.lang.Object
    Data migration of old formats to current format can be implemented in a concrete subclass and configured to be used by the JacksonSerializer for a changed class.

    It is used when deserializing data of older version than the currentVersion(). You implement the transformation of the JSON structure in the transform(int, com.fasterxml.jackson.databind.JsonNode) method. If you have changed the class name you should override transformClassName(int, java.lang.String) and return current class name.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract int currentVersion()
      Define current version, that is, the value used when serializing new data.
      int supportedForwardVersion()
      Define the supported forward version this migration can read (must be greater or equal than currentVersion).
      abstract com.fasterxml.jackson.databind.JsonNode transform​(int fromVersion, com.fasterxml.jackson.databind.JsonNode json)
      Implement the transformation of the old JSON structure to the new JSON structure.
      java.lang.String transformClassName​(int fromVersion, java.lang.String className)
      Override this method if you have changed the class name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JacksonMigration

        public JacksonMigration()
    • Method Detail

      • currentVersion

        public abstract int currentVersion()
        Define current version, that is, the value used when serializing new data. The first version, when no migration was used, is always 1.
      • supportedForwardVersion

        public int supportedForwardVersion()
        Define the supported forward version this migration can read (must be greater or equal than currentVersion). If this value is different from currentVersion() a JacksonMigration may be required to downcast the received payload to the current schema.
      • transform

        public abstract com.fasterxml.jackson.databind.JsonNode transform​(int fromVersion,
                                                                          com.fasterxml.jackson.databind.JsonNode json)
        Implement the transformation of the old JSON structure to the new JSON structure. The JsonNode is mutable so you can add and remove fields, or change values. Note that you have to cast to specific sub-classes such as ObjectNode and ArrayNode to get access to mutators.

        Parameters:
        fromVersion - the version of the old data
        json - the old JSON data
      • transformClassName

        public java.lang.String transformClassName​(int fromVersion,
                                                   java.lang.String className)
        Override this method if you have changed the class name. Return current class name.