mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +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.
|
// This includes assigning a primitive type to its equivalent "boxed" type.
|
||||||
val evolverPropertyType = evolverProperty.type.observedType.asClass()
|
val evolverPropertyType = evolverProperty.type.observedType.asClass()
|
||||||
evolverPropertyType.isAssignableFrom(propertyType)
|
evolverPropertyType.isAssignableFrom(propertyType)
|
||||||
|| (propertyType.isPrimitive && evolverPropertyType.isAssignableFrom(primitiveBoxedTypes[propertyType]
|
|| (propertyType.isPrimitive && evolverPropertyType.isAssignableFrom(boxed(propertyType)))
|
||||||
?: throw IllegalStateException("Unknown primitive type '$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>) {
|
private fun RemoteTypeInformation.Composable.validateEvolvability(localProperties: Map<PropertyName, LocalPropertyInformation>) {
|
||||||
val remotePropertyNames = properties.keys
|
val remotePropertyNames = properties.keys
|
||||||
val localPropertyNames = localProperties.keys
|
val localPropertyNames = localProperties.keys
|
||||||
|
@ -768,4 +768,27 @@ class EvolvabilityTests {
|
|||||||
assertEquals(1, deserializedCC.a)
|
assertEquals(1, deserializedCC.a)
|
||||||
assertEquals(42, deserializedCC.b)
|
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