From 1c7258aee00f0c3f9469c67f802a41ea2e12333b Mon Sep 17 00:00:00 2001 From: Joseph Zuniga-Daly Date: Thu, 25 Jun 2020 17:14:18 +0100 Subject: [PATCH] Add CheckpointCustomSerializer interface --- .../SerializationCustomSerializer.kt | 25 +++++++++++++++++++ ...ckNetworkCustomSerializerCheckpointTest.kt | 6 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt b/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt index d0c910b638..5e7fac1bba 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt @@ -25,3 +25,28 @@ interface SerializationCustomSerializer { */ fun fromProxy(proxy: PROXY): OBJ } + +/** + * Allows CorDapps to provide custom serializers for third party libraries where those libraries cannot + * be recompiled with the -parameters flag rendering their classes natively serializable by Corda. In this case + * a proxy serializer can be written that extends this type whose purpose is to move between those an + * unserializable types and an intermediate representation. + * + * NOTE: The proxy object should be specified as a separate class. However, this can be defined within the + * scope of the custom serializer. + */ +@KeepForDJVM +interface CheckpointCustomSerializer { + /** + * Should facilitate the conversion of the third party object into the serializable + * local class specified by [PROXY] + */ + fun toProxy(obj: OBJ): PROXY + + /** + * Should facilitate the conversion of the proxy object into a new instance of the + * unserializable type + */ + fun fromProxy(proxy: PROXY): OBJ + +} diff --git a/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt b/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt index 6ce4018c8b..a641835b36 100644 --- a/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt @@ -6,6 +6,7 @@ import com.github.andrewoma.dexx.kollection.immutableMapOf import com.github.andrewoma.dexx.kollection.toImmutableMap import net.corda.core.flows.FlowLogic import net.corda.core.flows.StartableByRPC +import net.corda.core.serialization.CheckpointCustomSerializer import net.corda.core.serialization.SerializationCustomSerializer import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetworkParameters @@ -92,7 +93,10 @@ class MockNetworkCustomSerializerCheckpointTest{ // Custom serializers @Suppress("unused") - class TestSerializer : SerializationCustomSerializer, HashMap> { + class TestSerializer : + SerializationCustomSerializer, HashMap>, + CheckpointCustomSerializer, HashMap> { + override fun toProxy(obj: ImmutableMap): HashMap { val proxy = HashMap() return obj.toMap(proxy)