Fixes for nullable Prim Types

Commit messages from Squashed Commits
    - Carpenter doesn't work with nullable prim types
    - Fix to get Cherry picks up to date with Master
This commit is contained in:
Katelyn Baker 2017-07-18 09:55:14 +01:00
parent a5106d74a8
commit 0541d128e4
3 changed files with 24 additions and 5 deletions

View File

@ -94,7 +94,7 @@ fun CompositeType.carpenterSchema(
fun AMQPField.getTypeAsClass(
classLoaders: List<ClassLoader> = listOf<ClassLoader> (ClassLoader.getSystemClassLoader())
) = when (type) {
"int" -> Int::class.javaPrimitiveType!!
"int" -> if (mandatory) Integer::class.java else Int::class.javaPrimitiveType!!
"string" -> String::class.java
"short" -> Short::class.javaPrimitiveType!!
"long" -> Long::class.javaPrimitiveType!!

View File

@ -2,10 +2,8 @@ package net.corda.core.serialization.amqp
import org.junit.Test
import kotlin.test.*
import net.corda.core.serialization.carpenter.ClassCarpenter
import net.corda.core.serialization.carpenter.ClassSchema
import net.corda.core.serialization.carpenter.InterfaceSchema
import net.corda.core.serialization.carpenter.NonNullableField
import net.corda.core.serialization.carpenter.*
import java.lang.Character
interface I {
fun getName() : String
@ -125,4 +123,24 @@ class DeserializeNeedingCarpentryTests {
assertEquals("timmy", deserializedObj::class.java.getMethod("getName").invoke(deserializedObj))
assertEquals(12, deserializedObj::class.java.getMethod("getAge").invoke(deserializedObj))
}
@Test
fun manyTypes() {
val cc = ClassCarpenter()
val manyClass = cc.build (ClassSchema(
"many",
mapOf(
"intA" to NonNullableField (Int::class.java),
"intB" to NullableField (Integer::class.java),
"strA" to NonNullableField (String::class.java),
"strB" to NullableField (String::class.java),
"charA" to NonNullableField (Char::class.java),
"charB" to NullableField (Character::class.java))))
val serialisedBytes = SerializationOutput().serialize(
manyClass.constructors.first().newInstance(1, 2, "a", "b", 'c', 'd'))
val deserializedObj = DeserializationInput().deserialize(serialisedBytes)
}
}

View File

@ -2,6 +2,7 @@ package net.corda.nodeapi.internal.serialization.carpenter
import net.corda.nodeapi.internal.serialization.amqp.Field
import net.corda.nodeapi.internal.serialization.amqp.Schema
import net.corda.nodeapi.internal.serialization.amqp.CompositeType
import net.corda.nodeapi.internal.serialization.amqp.SerializerFactory
import net.corda.nodeapi.internal.serialization.amqp.SerializationOutput