mirror of
https://github.com/corda/corda.git
synced 2025-03-13 07:54:32 +00:00
Add CheckpointCustomSerializer interface
This commit is contained in:
parent
050a36a677
commit
1c7258aee0
@ -25,3 +25,28 @@ interface SerializationCustomSerializer<OBJ, PROXY> {
|
||||
*/
|
||||
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<OBJ, PROXY> {
|
||||
/**
|
||||
* 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
|
||||
|
||||
}
|
||||
|
@ -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<ImmutableMap<Any, Any>, HashMap<Any, Any>> {
|
||||
class TestSerializer :
|
||||
SerializationCustomSerializer<ImmutableMap<Any, Any>, HashMap<Any, Any>>,
|
||||
CheckpointCustomSerializer<ImmutableMap<Any, Any>, HashMap<Any, Any>> {
|
||||
|
||||
override fun toProxy(obj: ImmutableMap<Any, Any>): HashMap<Any, Any> {
|
||||
val proxy = HashMap<Any, Any>()
|
||||
return obj.toMap(proxy)
|
||||
|
Loading…
x
Reference in New Issue
Block a user