diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializerFactory.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializerFactory.kt index b88c89d99c..363909d0b3 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializerFactory.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializerFactory.kt @@ -4,7 +4,6 @@ import com.google.common.primitives.Primitives import com.google.common.reflect.TypeResolver import net.corda.core.serialization.ClassWhitelist import net.corda.core.serialization.CordaSerializable -import net.corda.nodeapi.internal.serialization.AllWhitelist import net.corda.nodeapi.internal.serialization.carpenter.CarpenterSchemas import net.corda.nodeapi.internal.serialization.carpenter.ClassCarpenter import net.corda.nodeapi.internal.serialization.carpenter.MetaCarpenter @@ -182,13 +181,13 @@ class SerializerFactory(val whitelist: ClassWhitelist, cl : ClassLoader) { * Iterate over an AMQP schema, for each type ascertain weather it's on ClassPath of [classloader] amd * if not use the [ClassCarpenter] to generate a class to use in it's place */ - private fun processSchema(schema: Schema, sentinal: Boolean = false) { + private fun processSchema(schema: Schema, sentinel: Boolean = false) { val carpenterSchemas = CarpenterSchemas.newInstance() for (typeNotation in schema.types) { try { - } - catch (e: ClassNotFoundException) { - if (sentinal || (typeNotation !is CompositeType)) throw e + processSchemaEntry(typeNotation) + } catch (e: ClassNotFoundException) { + if (sentinel || (typeNotation !is CompositeType)) throw e typeNotation.carpenterSchema(classloader, carpenterSchemas = carpenterSchemas) } } @@ -209,13 +208,13 @@ class SerializerFactory(val whitelist: ClassWhitelist, cl : ClassLoader) { private fun processRestrictedType(typeNotation: RestrictedType) { // TODO: class loader logic, and compare the schema. - val type = typeForName(typeNotation.name) + val type = typeForName(typeNotation.name, classloader) get(null, type) } - private fun processCompositeType(typeNotation: CompositeType, + private fun processCompositeType(typeNotation: CompositeType) { // TODO: class loader logic, and compare the schema. - val type = typeForName(typeNotation.name, cl) + val type = typeForName(typeNotation.name, classloader) get(type.asClass() ?: throw NotSerializableException("Unable to build composite type for $type"), type) } diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentrySimpleTypesTest.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentrySimpleTypesTest.kt index 01fb68a22f..0a05542ad7 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentrySimpleTypesTest.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentrySimpleTypesTest.kt @@ -16,8 +16,8 @@ class DeserializeNeedingCarpentrySimpleTypesTest : AmqpCarpenterBase() { private const val VERBOSE = false } - val sf = SerializerFactory() - val sf2 = SerializerFactory() + val sf = testDefaultFactory() + val sf2 = testDefaultFactory() @Test fun singleInt() { diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentryTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentryTests.kt index d8feeb8473..585a362d15 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentryTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeNeedingCarpentryTests.kt @@ -25,8 +25,8 @@ class DeserializeNeedingCarpentryTests : AmqpCarpenterBase() { private const val VERBOSE = false } - val sf1 = SerializerFactory() - val sf2 = SerializerFactory() + val sf1 = testDefaultFactory() + val sf2 = testDefaultFactory() @Test fun verySimpleType() { @@ -165,7 +165,7 @@ class DeserializeNeedingCarpentryTests : AmqpCarpenterBase() { @Test fun nestedTypes() { val cc = ClassCarpenter() - val nestedClass = cc.build (ClassSchema(testName(), + val nestedClass = cc.build (ClassSchema("nestedType", mapOf("name" to NonNullableField(String::class.java)))) val outerClass = cc.build (ClassSchema("outerType", @@ -174,6 +174,23 @@ class DeserializeNeedingCarpentryTests : AmqpCarpenterBase() { val classInstance = outerClass.constructors.first().newInstance(nestedClass.constructors.first().newInstance("name")) val serialisedBytes = TestSerializationOutput(VERBOSE, sf1).serialize(classInstance) val deserializedObj = DeserializationInput(sf2).deserialize(serialisedBytes) + + val inner = deserializedObj::class.java.getMethod("getInner").invoke(deserializedObj) + assertEquals("name", inner::class.java.getMethod("getName").invoke(inner)) + } + + @Test + fun repeatedNestedTypes() { + val cc = ClassCarpenter() + val nestedClass = cc.build (ClassSchema("nestedType", + mapOf("name" to NonNullableField(String::class.java)))) + + data class outer(val a: Any, val b: Any) + + val classInstance = outer ( + nestedClass.constructors.first().newInstance("foo"), + nestedClass.constructors.first().newInstance("bar")) + val serialisedBytes = TestSerializationOutput(VERBOSE, sf1).serialize(classInstance) val deserializedObj = DeserializationInput(sf2).deserialize(serialisedBytes) diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeSimpleTypesTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeSimpleTypesTests.kt index 88ec97ca42..cc05b9b39f 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeSimpleTypesTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/DeserializeSimpleTypesTests.kt @@ -23,23 +23,23 @@ class DeserializeSimpleTypesTests { fun testChar() { data class C(val c: Char) - var deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('c'))) + var deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('c'))) assertEquals('c', deserializedC.c) // CYRILLIC CAPITAL LETTER YU (U+042E) - deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('Ю'))) + deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('Ю'))) assertEquals('Ю', deserializedC.c) // ARABIC LETTER FEH WITH DOT BELOW (U+06A3) - deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('ڣ'))) + deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('ڣ'))) assertEquals('ڣ', deserializedC.c) // ARABIC LETTER DAD WITH DOT BELOW (U+06FB) - deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('ۻ'))) + deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('ۻ'))) assertEquals('ۻ', deserializedC.c) // BENGALI LETTER AA (U+0986) - deserializedC = DeserializationInput(sf).deserialize(SerializationOutput(sf).serialize(C('আ'))) + deserializedC = DeserializationInput(sf1).deserialize(SerializationOutput(sf1).serialize(C('আ'))) assertEquals('আ', deserializedC.c) } @@ -49,8 +49,8 @@ class DeserializeSimpleTypesTests { data class C(val c: Character) val c = C(Character('c')) - val serialisedC = SerializationOutput(sf).serialize(c) - val deserializedC = DeserializationInput(sf).deserialize(serialisedC) + val serialisedC = SerializationOutput(sf1).serialize(c) + val deserializedC = DeserializationInput(sf1).deserialize(serialisedC) assertEquals(c.c, deserializedC.c) } @@ -60,8 +60,8 @@ class DeserializeSimpleTypesTests { data class C(val c: Char?) val c = C(null) - val serialisedC = SerializationOutput(sf).serialize(c) - val deserializedC = DeserializationInput(sf).deserialize(serialisedC) + val serialisedC = SerializationOutput(sf1).serialize(c) + val deserializedC = DeserializationInput(sf1).deserialize(serialisedC) assertEquals(c.c, deserializedC.c) }