mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
CORDA-3469: Allow EvolutionSerializer to handle boxed types becoming primitive. (#5766)
This commit is contained in:
parent
f7328f18f4
commit
5ce1535ea5
@ -114,13 +114,17 @@ class DefaultEvolutionSerializerFactory(
|
||||
// This includes assigning a primitive type to its equivalent "boxed" type.
|
||||
val evolverPropertyType = evolverProperty.type.observedType.asClass()
|
||||
evolverPropertyType.isAssignableFrom(propertyType)
|
||||
|| (propertyType.isPrimitive && evolverPropertyType.isAssignableFrom(primitiveBoxedTypes[propertyType]
|
||||
?: throw IllegalStateException("Unknown primitive type '$propertyType'")))
|
||||
|| (propertyType.isPrimitive && evolverPropertyType.isAssignableFrom(boxed(propertyType)))
|
||||
|| (evolverPropertyType.isPrimitive && boxed(evolverPropertyType).isAssignableFrom(propertyType))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun boxed(primitiveType: Class<*>): Class<*> {
|
||||
return primitiveBoxedTypes[primitiveType] ?: throw IllegalStateException("Unknown primitive type '$primitiveType'")
|
||||
}
|
||||
|
||||
private fun RemoteTypeInformation.Composable.validateEvolvability(localProperties: Map<PropertyName, LocalPropertyInformation>) {
|
||||
val remotePropertyNames = properties.keys
|
||||
val localPropertyNames = localProperties.keys
|
||||
|
@ -768,4 +768,27 @@ class EvolvabilityTests {
|
||||
assertEquals(1, deserializedCC.a)
|
||||
assertEquals(42, deserializedCC.b)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addMandatoryFieldWithAltConstructorAndMakeExistingNullableIntFieldMandatory() {
|
||||
val sf = testDefaultFactory()
|
||||
val resource = "EvolvabilityTests.addMandatoryFieldWithAltConstructorAndMakeExistingNullableIntFieldMandatory"
|
||||
|
||||
// Original version of the class as it was serialised
|
||||
// data class CC(val a: Int?)
|
||||
// File(URI("$localPath/$resource")).writeBytes(SerializationOutput(sf).serialize(CC(null)).bytes)
|
||||
|
||||
data class CC(val a: Int, val b: Int) {
|
||||
@DeprecatedConstructorForDeserialization(1)
|
||||
@Suppress("unused")
|
||||
constructor(a: Int?) : this(a ?: -1,42)
|
||||
}
|
||||
|
||||
val url = EvolvabilityTests::class.java.getResource(resource) ?: fail("Not found!")
|
||||
val sc2 = url.readBytes()
|
||||
val deserializedCC = DeserializationInput(sf).deserialize(SerializedBytes<CC>(sc2))
|
||||
|
||||
assertEquals(-1, deserializedCC.a)
|
||||
assertEquals(42, deserializedCC.b)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user