CORDA-2742 treat boxed types as assignable from primitives (#4890)

This commit is contained in:
Dominic Fox 2019-03-15 15:16:14 +00:00 committed by Shams Asari
parent e3ada049d4
commit 345a76d1cd
3 changed files with 28 additions and 1 deletions

View File

@ -76,7 +76,7 @@ class DefaultEvolutionSerializerFactory(
val localClass = localProperty.type.observedType.asClass()
val remoteClass = remoteProperty.type.typeIdentifier.getLocalType(classLoader).asClass()
if (!localClass.isAssignableFrom(remoteClass)) {
if (!localClass.isAssignableFrom(remoteClass) && remoteClass != localClass.kotlin.javaPrimitiveType) {
throw EvolutionSerializationException(this,
"Local type $localClass of property $name is not assignable from remote type $remoteClass")
}

View File

@ -711,4 +711,31 @@ class EvolvabilityTests {
assertEquals("dronf", deserialized.fnord)
}
// Container class
data class ParameterizedContainer(val parameterized: Parameterized<Int, Int>?)
// Class as it was serialized
// data class Parameterized<A, B>(val a: A, val b: Set<B>)
// Marker interface to force evolution
interface ForceEvolution
// Class after evolution
data class Parameterized<A, B>(val a: A, val b: Set<B>) : ForceEvolution
// See CORDA-2742
@Test
fun evolutionWithPrimitives() {
val resource = "EvolvabilityTests.evolutionWithPrimitives"
val sf = testDefaultFactory()
// Uncomment to recreate
// File(URI("$localPath/$resource")).writeBytes(SerializationOutput(sf).serialize(ParameterizedContainer(Parameterized(10, setOf(20)))).bytes)
val url = EvolvabilityTests::class.java.getResource(resource)
val sc2 = url.readBytes()
val deserialized = DeserializationInput(sf).deserialize(SerializedBytes<ParameterizedContainer>(sc2))
assertEquals(10, deserialized.parameterized?.a)
}
}