CORDA-2263 evolve types with calculated properties (#4314)

* CORDA-2263 evolve types with calculated properties

* Push handling of computed properties into builders

* Set isAccessible to true prior to calling

* Type information captures Java constructor, not Kotlin wrapper
This commit is contained in:
Dominic Fox
2018-11-29 15:54:30 +00:00
committed by GitHub
parent 9100636b8c
commit 488f11e2e6
7 changed files with 192 additions and 61 deletions

View File

@ -7,6 +7,7 @@ import net.corda.core.node.NetworkParameters
import net.corda.core.node.NotaryInfo
import net.corda.core.serialization.ConstructorForDeserialization
import net.corda.core.serialization.DeprecatedConstructorForDeserialization
import net.corda.core.serialization.SerializableCalculatedProperty
import net.corda.core.serialization.SerializedBytes
import net.corda.serialization.internal.amqp.testutils.*
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
@ -149,6 +150,34 @@ class EvolvabilityTests {
assertEquals(D, deserializedCC.d)
}
@Suppress("UNUSED_VARIABLE")
@Test
fun removeParameterWithCalculatedParameter() {
val sf = testDefaultFactory()
val resource = "EvolvabilityTests.removeParameterWithCalculatedParameter"
// Original version of the class as it was serialised
// data class CC(val a: Int, val b: String, val c: String, val d: Int) {
// @get:SerializableCalculatedProperty
// val e: String get() = "$b $c"
// }
// File(URI("$localPath/$resource")).writeBytes(SerializationOutput(sf).serialize(CC(1, "hello", "world", 2)).bytes)
data class CC(val b: String, val d: Int) {
@get:SerializableCalculatedProperty
val e: String get() = "$b sailor"
}
val url = EvolvabilityTests::class.java.getResource(resource)
val sc2 = url.readBytes()
val deserializedCC = DeserializationInput(sf).deserialize(SerializedBytes<CC>(sc2))
assertEquals("hello", deserializedCC.b)
assertEquals(2, deserializedCC.d)
assertEquals("hello sailor", deserializedCC.e)
}
@Suppress("UNUSED_VARIABLE")
@Test
fun addAndRemoveParameters() {