Package akka.javasdk

Class JsonMigration

Object
akka.javasdk.JsonMigration

public abstract class JsonMigration extends Object
Allows to specify dedicated strategy for JSON schema evolution.

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 add it to supportedClassNames().

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract int
    Define current version, that is, the value used when serializing new data.
    Override this method if you have changed the class name.
    int
    Define the supported forward version this migration can read (must be greater or equal than currentVersion).
    com.fasterxml.jackson.databind.JsonNode
    transform(int fromVersion, com.fasterxml.jackson.databind.JsonNode json)
    Implement the transformation of the incoming JSON structure to the current JSON structure.

    Methods inherited from class java.lang.Object

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

    • JsonMigration

      public JsonMigration()
  • Method Details

    • 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 0.
    • 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 transform(int, com.fasterxml.jackson.databind.JsonNode) will be used to downcast the received payload to the current schema.
    • transform

      public com.fasterxml.jackson.databind.JsonNode transform(int fromVersion, com.fasterxml.jackson.databind.JsonNode json)
      Implement the transformation of the incoming JSON structure to the current 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 incoming JSON data
    • supportedClassNames

      public List<String> supportedClassNames()
      Override this method if you have changed the class name. Return all old class names.