mirror of
https://github.com/corda/corda.git
synced 2025-01-18 02:39:51 +00:00
Serialising null chars was broken
The recent changes that were put in to allow chars to be serialised at all failed to take into account nullability and thus if a char was null and that object was first serlialised then desierliased it would throw a NPE
This commit is contained in:
parent
c721316d67
commit
06a8a4bada
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Int>)
|
||||
|
Loading…
Reference in New Issue
Block a user