CordaSerializationTransformEnumDefault.old - corda

corda / net.corda.core.serialization / CordaSerializationTransformEnumDefault / old

# old

`val old: String`

String equivalent of the value of the existing constant that deserialisers should favour when de-serialising a value they have no corresponding value for

For Example

Enum before modification:

    enum class ExampleEnum {
      A, B, C
    }

Assuming at some point a new constant is added it is required we have some mechanism by which to tell nodes with an older version of the class on their Class Path what to do if they attempt to deserialize an example of the class with that new value

    @CordaSerializationTransformEnumDefault("D", "C")
    enum class ExampleEnum {
      A, B, C, D
    }

So, on deserialisation treat any instance of the enum that is encoded as D as C

Adding a second new constant requires the wrapper annotation CordaSerializationTransformEnumDefaults

    @CordaSerializationTransformEnumDefaults(
        CordaSerializationTransformEnumDefault("E", "D"),
        CordaSerializationTransformEnumDefault("D", "C"))
    enum class ExampleEnum {
      A, B, C, D, E
    }

It's fine to assign the second new value a default that may not be present in all versions as in this case it will work down the transform hierarchy until it finds a value it can apply, in this case it would try E -> D -> C (when E -> D fails)

### Property

`old` -

String equivalent of the value of the existing constant that deserialisers should favour when de-serialising a value they have no corresponding value for

For Example

Enum before modification:

    enum class ExampleEnum {
      A, B, C
    }

Assuming at some point a new constant is added it is required we have some mechanism by which to tell nodes with an older version of the class on their Class Path what to do if they attempt to deserialize an example of the class with that new value

    @CordaSerializationTransformEnumDefault("D", "C")
    enum class ExampleEnum {
      A, B, C, D
    }

So, on deserialisation treat any instance of the enum that is encoded as D as C

Adding a second new constant requires the wrapper annotation CordaSerializationTransformEnumDefaults

    @CordaSerializationTransformEnumDefaults(
        CordaSerializationTransformEnumDefault("E", "D"),
        CordaSerializationTransformEnumDefault("D", "C"))
    enum class ExampleEnum {
      A, B, C, D, E
    }

It's fine to assign the second new value a default that may not be present in all versions as in this case it will work down the transform hierarchy until it finds a value it can apply, in this case it would try E -> D -> C (when E -> D fails)