diff --git a/core/src/main/kotlin/net/corda/core/serialization/amqp/PropertySerializer.kt b/core/src/main/kotlin/net/corda/core/serialization/amqp/PropertySerializer.kt index 0211af8541..5ac754af18 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/amqp/PropertySerializer.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/amqp/PropertySerializer.kt @@ -113,13 +113,16 @@ sealed class PropertySerializer(val name: String, val readMethod: Method, val re * casting back to a char otherwise it's treated as an Integer and a TypeMismatch occurs */ class AMQPCharPropertySerializer(name: String, readMethod: Method) : - PropertySerializer(name, readMethod, Char::class.java) { + PropertySerializer(name, readMethod, Character::class.java) { override fun writeClassInfo(output: SerializationOutput) {} - override fun readProperty(obj: Any?, schema: Schema, input: DeserializationInput) = (obj as Int).toChar() + override fun readProperty(obj: Any?, schema: Schema, input: DeserializationInput): Any? { + return if(obj == null) null else (obj as Int).toChar() + } override fun writeProperty(obj: Any?, data: Data, output: SerializationOutput) { - data.putChar((readMethod.invoke(obj) as Char).toInt()) + val input = readMethod.invoke(obj) + if (input != null) data.putChar((input as Char).toInt()) else data.putNull() } } } diff --git a/core/src/test/kotlin/net/corda/core/serialization/amqp/DeserializeSimpleTypesTests.kt b/core/src/test/kotlin/net/corda/core/serialization/amqp/DeserializeSimpleTypesTests.kt index 35e322fcdc..7ce9789d78 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/amqp/DeserializeSimpleTypesTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/amqp/DeserializeSimpleTypesTests.kt @@ -50,6 +50,17 @@ class DeserializeSimpleTypesTests { assertEquals(c.c, deserializedC.c) } + @Test + fun testNullCharacter() { + data class C(val c: Char?) + + val c = C(null) + val serialisedC = SerializationOutput().serialize(c) + val deserializedC = DeserializationInput().deserialize(serialisedC) + + assertEquals(c.c, deserializedC.c) + } + @Test fun testArrayOfInt() { class IA(val ia: Array)