mirror of
https://github.com/corda/corda.git
synced 2025-06-04 08:30:52 +00:00
CORDA-2742 treat boxed types as assignable from primitives (#4890)
This commit is contained in:
parent
e3ada049d4
commit
345a76d1cd
@ -76,7 +76,7 @@ class DefaultEvolutionSerializerFactory(
|
|||||||
val localClass = localProperty.type.observedType.asClass()
|
val localClass = localProperty.type.observedType.asClass()
|
||||||
val remoteClass = remoteProperty.type.typeIdentifier.getLocalType(classLoader).asClass()
|
val remoteClass = remoteProperty.type.typeIdentifier.getLocalType(classLoader).asClass()
|
||||||
|
|
||||||
if (!localClass.isAssignableFrom(remoteClass)) {
|
if (!localClass.isAssignableFrom(remoteClass) && remoteClass != localClass.kotlin.javaPrimitiveType) {
|
||||||
throw EvolutionSerializationException(this,
|
throw EvolutionSerializationException(this,
|
||||||
"Local type $localClass of property $name is not assignable from remote type $remoteClass")
|
"Local type $localClass of property $name is not assignable from remote type $remoteClass")
|
||||||
}
|
}
|
||||||
|
@ -711,4 +711,31 @@ class EvolvabilityTests {
|
|||||||
|
|
||||||
assertEquals("dronf", deserialized.fnord)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user