deserializationcorda

Data class file location change in CorDapp


I heard that, if we change the Corda state or contract's location in a CorDapp, it will be considered as a new state or contract and will have conflict with existing data.

Is it okay to change the file location of a data class in a CorDapp which is a datatype of a state parameter, considering older data is present in environments.

(for eg: will it throw error in terms of deserialization)?


Solution

  • The AMQP serialized data in Corda has the fully qualified class name. When deserializing, it will ask its class loader to load that class, and expects a constructor that allows it to construct an instance with the fields that have been serialized. So if your class has the correct constructor and the same fully qualified name, the file location of your source code file does not matter.

    Having said that - if you move a file around in a Java solution and this changes the package name, it will be considered a different class and will fail to deserialize.