Review Comments

* Typos in comments
 * Refactor some one liners
This commit is contained in:
Katelyn Baker 2017-08-24 17:33:21 +01:00
parent e4a2529de0
commit dda9d22264
3 changed files with 15 additions and 20 deletions

View File

@ -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)

View File

@ -19,15 +19,15 @@ class EvolutionSerializer(
val readers: List<OldParam?>,
override val kotlinConstructor: KFunction<Any>?) : ObjectSerializer(clazz, factory) {
// explicitly null this out as we won't be using this list
override val propertySerializers: Collection<PropertySerializer> = listOf()
// explicitly set as empty to indicate it's unused by this type of serializer
override val propertySerializers: Collection<PropertySerializer> = 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<String, OldParam>()
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")

View File

@ -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<Any> {
override val type: Type get() = clazz
open internal val propertySerializers: Collection<PropertySerializer>
open val kotlinConstructor = constructorForDeserialization(clazz)
val javaConstructor by lazy { kotlinConstructor?.javaConstructor }
init {
propertySerializers = propertiesForSerialization(kotlinConstructor, clazz, factory)
open internal val propertySerializers: Collection<PropertySerializer> 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<String> {
return interfaces.map { nameForType(it) }
}
private fun generateProvides(): List<String> = interfaces.map { nameForType(it) }
fun construct(properties: List<Any?>): Any {
if (javaConstructor == null) {
fun construct(properties: List<Any?>) = javaConstructor?.newInstance(*properties.toTypedArray()) ?:
throw NotSerializableException("Attempt to deserialize an interface: $clazz. Serialized form is invalid.")
}
return javaConstructor!!.newInstance(*properties.toTypedArray())
}
}