CORDA-553 - Review comments

This commit is contained in:
Katelyn Baker 2017-12-08 11:49:05 +00:00
parent 8878fa99a0
commit c396842b0e
4 changed files with 14 additions and 15 deletions

View File

@ -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 * a proxy serializer can be written that extends this type whose purpose is to move between those an
* unserializable types and an intermediate representation. * 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. * scope of the custom serializer.
*/ */
interface SerializationCustomSerializer<OBJ, PROXY> { interface SerializationCustomSerializer<OBJ, PROXY> {

View File

@ -68,9 +68,9 @@ abstract class AbstractAMQPSerializationScheme(val cordappLoader: List<Cordapp>)
factory.addToWhitelist(*whitelistProvider.whitelist.toTypedArray()) factory.addToWhitelist(*whitelistProvider.whitelist.toTypedArray())
} }
cordappLoader.forEach { ca -> for (loader in cordappLoader) {
ca.serializationCustomSerializers.forEach { for (schema in loader.serializationCustomSerializers) {
factory.registerExternal(CorDappCustomSerializer(it, factory)) factory.registerExternal(CorDappCustomSerializer(schema, factory))
} }
} }
} }

View File

@ -36,8 +36,8 @@ const val PROXY_TYPE = 1
* automatically * automatically
* @property type the Java [Type] of the class which this serializes, inferred via reflection of the * @property type the Java [Type] of the class which this serializes, inferred via reflection of the
* [serializer]'s super type * [serializer]'s super type
* @property proxyType the Java [Type] of the class into which instances of [type] are proxied for use byt * @property proxyType the Java [Type] of the class into which instances of [type] are proxied for use by
* the underlying serialisation engine * the underlying serialization engine
* *
* @param factory a [SerializerFactory] belonging to the context this serializer is being instantiated * @param factory a [SerializerFactory] belonging to the context this serializer is being instantiated
* for * for
@ -58,17 +58,15 @@ class CorDappCustomSerializer(
override val type = types[CORDAPP_TYPE] override val type = types[CORDAPP_TYPE]
val proxyType = types[PROXY_TYPE] val proxyType = types[PROXY_TYPE]
override val typeDescriptor = Symbol.valueOf("$DESCRIPTOR_DOMAIN:${nameForType(type)}") override val typeDescriptor = Symbol.valueOf("$DESCRIPTOR_DOMAIN:${nameForType(type)}")
val descriptor: Descriptor = Descriptor(typeDescriptor) val descriptor: Descriptor = Descriptor(typeDescriptor)
private val proxySerializer: ObjectSerializer by lazy { ObjectSerializer(proxyType, factory) } private val proxySerializer: ObjectSerializer by lazy { ObjectSerializer(proxyType, factory) }
override fun writeClassInfo(output: SerializationOutput) {} override fun writeClassInfo(output: SerializationOutput) {}
override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput) { override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput) {
val proxy = uncheckedCast<SerializationCustomSerializer<*, *>, val proxy = uncheckedCast<SerializationCustomSerializer<*, *>,
SerializationCustomSerializer<Any?,Any?>> (serializer).toProxy(obj) SerializationCustomSerializer<Any?, Any?>>(serializer).toProxy(obj)
data.withDescribed(descriptor) { data.withDescribed(descriptor) {
data.withList { data.withList {
@ -80,7 +78,7 @@ class CorDappCustomSerializer(
} }
override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput) = override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput) =
uncheckedCast<SerializationCustomSerializer<*, *>, SerializationCustomSerializer<Any?,Any?>> ( uncheckedCast<SerializationCustomSerializer<*, *>, SerializationCustomSerializer<Any?, Any?>>(
serializer).fromProxy(uncheckedCast(proxySerializer.readObject(obj, schemas, input)))!! serializer).fromProxy(uncheckedCast(proxySerializer.readObject(obj, schemas, input)))!!
override fun isSerializerFor(clazz: Class<*>) = clazz == type override fun isSerializerFor(clazz: Class<*>) = clazz == type

View File

@ -10,8 +10,10 @@ import net.corda.core.internal.*
import net.corda.core.internal.cordapp.CordappImpl import net.corda.core.internal.cordapp.CordappImpl
import net.corda.core.node.services.CordaService import net.corda.core.node.services.CordaService
import net.corda.core.schemas.MappedSchema 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.utilities.contextLogger
import net.corda.core.serialization.*
import net.corda.node.internal.classloading.requireAnnotation import net.corda.node.internal.classloading.requireAnnotation
import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.NodeConfiguration
import net.corda.nodeapi.internal.serialization.DefaultWhitelist import net.corda.nodeapi.internal.serialization.DefaultWhitelist
@ -197,7 +199,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
findSchedulableFlows(scanResult), findSchedulableFlows(scanResult),
findServices(scanResult), findServices(scanResult),
findPlugins(it), findPlugins(it),
findSerialzers(scanResult), findSerializers(scanResult),
findCustomSchemas(scanResult), findCustomSchemas(scanResult),
it.url) it.url)
} }
@ -248,8 +250,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List<Restri
} + DefaultWhitelist // Always add the DefaultWhitelist to the whitelist for an app. } + DefaultWhitelist // Always add the DefaultWhitelist to the whitelist for an app.
} }
private fun findSerialzers(scanResult: RestrictedScanResult) : List<SerializationCustomSerializer<*, *>> { private fun findSerializers(scanResult: RestrictedScanResult): List<SerializationCustomSerializer<*, *>> {
// return scanResult.getClassesWithAnnotation(SerializationCustomSerializer::class, CordaCustomSerializer::class)
return scanResult.getClassesImplementing(SerializationCustomSerializer::class) return scanResult.getClassesImplementing(SerializationCustomSerializer::class)
} }