From c396842b0e1520dc613ff08041e4a50a580de9b9 Mon Sep 17 00:00:00 2001 From: Katelyn Baker Date: Fri, 8 Dec 2017 11:49:05 +0000 Subject: [PATCH] CORDA-553 - Review comments --- .../serialization/SerializationCustomSerializer.kt | 4 ++-- .../serialization/amqp/AMQPSerializationScheme.kt | 6 +++--- .../serialization/amqp/CorDappCustomSerializer.kt | 10 ++++------ .../net/corda/node/internal/cordapp/CordappLoader.kt | 9 +++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt b/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt index bf81af2898..2ad2aded38 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt @@ -6,7 +6,7 @@ package net.corda.core.serialization * a proxy serializer can be written that extends this type whose purpose is to move between those an * unserializable types and an intermediate representation. * - * NOTE: The proxy object must should be specified as a seperate class. However, this can be defined within the + * NOTE: The proxy object should be specified as a seperate class. However, this can be defined within the * scope of the custom serializer. */ interface SerializationCustomSerializer { @@ -21,4 +21,4 @@ interface SerializationCustomSerializer { * unserializable type */ fun fromProxy(proxy: PROXY) : OBJ -} \ No newline at end of file +} diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPSerializationScheme.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPSerializationScheme.kt index ea4c90ebf5..00a7825d06 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPSerializationScheme.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPSerializationScheme.kt @@ -68,9 +68,9 @@ abstract class AbstractAMQPSerializationScheme(val cordappLoader: List) factory.addToWhitelist(*whitelistProvider.whitelist.toTypedArray()) } - cordappLoader.forEach { ca -> - ca.serializationCustomSerializers.forEach { - factory.registerExternal(CorDappCustomSerializer(it, factory)) + for (loader in cordappLoader) { + for (schema in loader.serializationCustomSerializers) { + factory.registerExternal(CorDappCustomSerializer(schema, factory)) } } } diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt index eaa27db161..72373488b3 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt @@ -36,8 +36,8 @@ const val PROXY_TYPE = 1 * automatically * @property type the Java [Type] of the class which this serializes, inferred via reflection of the * [serializer]'s super type - * @property proxyType the Java [Type] of the class into which instances of [type] are proxied for use byt - * the underlying serialisation engine + * @property proxyType the Java [Type] of the class into which instances of [type] are proxied for use by + * the underlying serialization engine * * @param factory a [SerializerFactory] belonging to the context this serializer is being instantiated * for @@ -58,17 +58,15 @@ class CorDappCustomSerializer( override val type = types[CORDAPP_TYPE] val proxyType = types[PROXY_TYPE] - override val typeDescriptor = Symbol.valueOf("$DESCRIPTOR_DOMAIN:${nameForType(type)}") val descriptor: Descriptor = Descriptor(typeDescriptor) - private val proxySerializer: ObjectSerializer by lazy { ObjectSerializer(proxyType, factory) } override fun writeClassInfo(output: SerializationOutput) {} override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput) { val proxy = uncheckedCast, - SerializationCustomSerializer> (serializer).toProxy(obj) + SerializationCustomSerializer>(serializer).toProxy(obj) data.withDescribed(descriptor) { data.withList { @@ -80,7 +78,7 @@ class CorDappCustomSerializer( } override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput) = - uncheckedCast, SerializationCustomSerializer> ( + uncheckedCast, SerializationCustomSerializer>( serializer).fromProxy(uncheckedCast(proxySerializer.readObject(obj, schemas, input)))!! override fun isSerializerFor(clazz: Class<*>) = clazz == type diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt index 38f20c951a..50f0140338 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt @@ -10,8 +10,10 @@ import net.corda.core.internal.* import net.corda.core.internal.cordapp.CordappImpl import net.corda.core.node.services.CordaService import net.corda.core.schemas.MappedSchema +import net.corda.core.serialization.SerializationCustomSerializer +import net.corda.core.serialization.SerializationWhitelist +import net.corda.core.serialization.SerializeAsToken import net.corda.core.utilities.contextLogger -import net.corda.core.serialization.* import net.corda.node.internal.classloading.requireAnnotation import net.corda.node.services.config.NodeConfiguration import net.corda.nodeapi.internal.serialization.DefaultWhitelist @@ -197,7 +199,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List> { -// return scanResult.getClassesWithAnnotation(SerializationCustomSerializer::class, CordaCustomSerializer::class) + private fun findSerializers(scanResult: RestrictedScanResult): List> { return scanResult.getClassesImplementing(SerializationCustomSerializer::class) }