diff --git a/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt b/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt index 37f0b53f34..71d2691e7e 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt @@ -1,8 +1,11 @@ package net.corda.core.serialization /** - * This annotation is a marker to indicate which secondary constructors shuold be considered, and in which + * This annotation is a marker to indicate which secondary constructors should be considered, and in which * order, for evolving objects during their deserialisation. + * + * Versions will be considered in descending order, currently duplicate versions will result in + * non deterministic behaviour when deserialising objects */ @Target(AnnotationTarget.CONSTRUCTOR) @Retention(AnnotationRetention.RUNTIME) diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt index 4c8b946a57..2632b4b46d 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt @@ -19,15 +19,15 @@ class EvolutionSerializer( val readers: List, override val kotlinConstructor: KFunction?) : ObjectSerializer(clazz, factory) { - // explicitly null this out as we won't be using this list - override val propertySerializers: Collection = listOf() + // explicitly set as empty to indicate it's unused by this type of serializer + override val propertySerializers: Collection = emptyList() /** - * represents a parameter as would be passed to the constructor of the class as it was + * Represents a parameter as would be passed to the constructor of the class as it was * when it was serialised and NOT how that class appears now * * @param type The jvm type of the parameter - * @param idx where in the parameter list this parameter falls. required as the parameter + * @param idx where in the parameter list this parameter falls. Required as the parameter * order may have been changed and we need to know where into the list to look * @param property object to read the actual property value */ @@ -87,7 +87,7 @@ class EvolutionSerializer( val constructor = getEvolverConstructor(new.type, oldFieldToType) ?: throw NotSerializableException( - "Attempt to deserialize an interface: new.type. Serialized form is invalid.") + "Attempt to deserialize an interface: ${new.type}. Serialized form is invalid.") val oldArgs = mutableMapOf() var idx = 0 @@ -118,6 +118,8 @@ class EvolutionSerializer( * constructor of the original state of the object, we need to map the new parameter order * of the current constructor onto that list inserting nulls where new parameters are * encountered + * + * TODO: Object references */ override fun readObject(obj: Any, schema: Schema, input: DeserializationInput): Any { if (obj !is List<*>) throw NotSerializableException("Body of described type is unexpected $obj") diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ObjectSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ObjectSerializer.kt index da29d36e45..3b99e84371 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ObjectSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ObjectSerializer.kt @@ -4,7 +4,6 @@ import net.corda.nodeapi.internal.serialization.amqp.SerializerFactory.Companion import org.apache.qpid.proton.amqp.UnsignedInteger import org.apache.qpid.proton.codec.Data import java.io.NotSerializableException -import java.lang.reflect.Constructor import java.lang.reflect.Type import kotlin.reflect.jvm.javaConstructor @@ -13,12 +12,11 @@ import kotlin.reflect.jvm.javaConstructor */ open class ObjectSerializer(val clazz: Type, factory: SerializerFactory) : AMQPSerializer { override val type: Type get() = clazz - open internal val propertySerializers: Collection open val kotlinConstructor = constructorForDeserialization(clazz) val javaConstructor by lazy { kotlinConstructor?.javaConstructor } - init { - propertySerializers = propertiesForSerialization(kotlinConstructor, clazz, factory) + open internal val propertySerializers: Collection by lazy { + propertiesForSerialization(kotlinConstructor, clazz, factory) } private val typeName = nameForType(clazz) @@ -66,16 +64,8 @@ open class ObjectSerializer(val clazz: Type, factory: SerializerFactory) : AMQPS return propertySerializers.map { Field(it.name, it.type, it.requires, it.default, null, it.mandatory, false) } } - private fun generateProvides(): List { - return interfaces.map { nameForType(it) } - } + private fun generateProvides(): List = interfaces.map { nameForType(it) } - - fun construct(properties: List): Any { - if (javaConstructor == null) { + fun construct(properties: List) = javaConstructor?.newInstance(*properties.toTypedArray()) ?: throw NotSerializableException("Attempt to deserialize an interface: $clazz. Serialized form is invalid.") - } - - return javaConstructor!!.newInstance(*properties.toTypedArray()) - } } \ No newline at end of file