diff --git a/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt b/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt index d4df6eb5ec..959f0e79d1 100644 --- a/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt +++ b/core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt @@ -39,7 +39,7 @@ interface Cordapp { val services: List> val serializationWhitelists: List val serializationCustomSerializerProxies: List> - val serializationCustomSerializers: List> + val serializationCustomSerializers: List>> val customSchemas: Set val jarPath: URL val cordappClasses: List diff --git a/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt b/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt index 7aaab3b8b3..f644a9890d 100644 --- a/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt +++ b/core/src/main/kotlin/net/corda/core/internal/cordapp/CordappImpl.kt @@ -18,7 +18,7 @@ data class CordappImpl( override val services: List>, override val serializationWhitelists: List, override val serializationCustomSerializerProxies: List>, - override val serializationCustomSerializers: List>, + override val serializationCustomSerializers: List>>, override val customSchemas: Set, override val jarPath: URL) : Cordapp { override val name: String = File(jarPath.toURI()).name.removeSuffix(".jar") 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 0f384196f5..d5fb39d30e 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/SerializationCustomSerializer.kt @@ -21,18 +21,18 @@ import java.lang.reflect.Type * @property type the type of the object that this class is proxying * @property ptype the type of the proxy object used as an intermediate representation of [type] */ -interface SerializationCustomSerializer { +interface SerializationCustomSerializer { /** * Should facilitate the conversion of the third party object into the serializable * local class specified by [ptype] */ - fun toProxy(obj: Any) : Any + fun toProxy(obj: OBJ) : PROXY /** * Should facilitate the conversion of the proxy object into a new instance of the * unserializable type */ - fun fromProxy(proxy: Any) : Any + fun fromProxy(proxy: PROXY) : OBJ /** * Should be set to the type of the object being proxied diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt index 87be4312d1..cdf6d59325 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CorDappCustomSerializer.kt @@ -8,7 +8,7 @@ import org.apache.qpid.proton.codec.Data import java.lang.reflect.Type class CorDappCustomSerializer( - private val serialiser: SerializationCustomSerializer, + private val serialiser: SerializationCustomSerializer<*, *>, factory: SerializerFactory) : AMQPSerializer, SerializerFor { override val revealSubclassesInSchema: Boolean get() = false @@ -21,7 +21,8 @@ class CorDappCustomSerializer( override fun writeClassInfo(output: SerializationOutput) {} override fun writeObject(obj: Any, data: Data, type: Type, output: SerializationOutput) { - val proxy = serialiser.toProxy(obj) + @Suppress("UNCHECKED_CAST") + val proxy = (serialiser as SerializationCustomSerializer).toProxy(obj) data.withDescribed(descriptor) { data.withList { @@ -32,9 +33,10 @@ class CorDappCustomSerializer( } } - override fun readObject(obj: Any, schema: Schema, input: DeserializationInput): Any { - return serialiser.fromProxy(uncheckedCast(proxySerializer.readObject(obj, schema, input))) - } + override fun readObject(obj: Any, schema: Schema, input: DeserializationInput) = + @Suppress("UNCHECKED_CAST") + (serialiser as SerializationCustomSerializer).fromProxy( + uncheckedCast(proxySerializer.readObject(obj, schema, input)))!! override fun isSerializerFor(clazz: Class<*>): Boolean = clazz == type } diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt index 7dc11cbeb7..7688a611db 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt @@ -254,7 +254,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List> { + private fun findSerialzers(scanResult: RestrictedScanResult) : List>> { return scanResult.getClassesWithAnnotation(SerializationCustomSerializer::class, CordaCustomSerializer::class) } diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitiesSerializer.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitiesSerializer.kt index 5d77d98e3d..42eb965689 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitiesSerializer.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitiesSerializer.kt @@ -9,13 +9,14 @@ import java.lang.reflect.Type @CordaCustomSerializer @Suppress("UNUSED") -class CurrencyParameterSensitivitiesSerializer : SerializationCustomSerializer { +class CurrencyParameterSensitivitiesSerializer : + SerializationCustomSerializer { @CordaCustomSerializerProxy data class Proxy(val sensitivities: List) override val type: Type get() = CurrencyParameterSensitivities::class.java override val ptype: Type get() = Proxy::class.java - override fun fromProxy(proxy: Any): Any = CurrencyParameterSensitivities.of ((proxy as Proxy).sensitivities) - override fun toProxy(obj: Any): Any = Proxy ((obj as CurrencyParameterSensitivities).sensitivities) + override fun fromProxy(proxy: Proxy) = CurrencyParameterSensitivities.of(proxy.sensitivities) + override fun toProxy(obj: CurrencyParameterSensitivities) = Proxy(obj.sensitivities) } \ No newline at end of file diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitySerialiser.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitySerialiser.kt index 7de99cac66..98dde48d8d 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitySerialiser.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencyParameterSensitivitySerialiser.kt @@ -12,7 +12,8 @@ import java.lang.reflect.Type @CordaCustomSerializer @Suppress("UNUSED") -class CurrencyParameterSensitivitySerializer : SerializationCustomSerializer { +class CurrencyParameterSensitivitySerializer : + SerializationCustomSerializer { @CordaCustomSerializerProxy data class Proxy(val currency: Currency, val marketDataName: MarketDataName<*>, val parameterMetadata: List, @@ -21,13 +22,13 @@ class CurrencyParameterSensitivitySerializer : SerializationCustomSerializer { override val type: Type get() = CurrencyParameterSensitivity::class.java override val ptype: Type get() = Proxy::class.java - override fun fromProxy(proxy: Any): Any = + override fun fromProxy(proxy: CurrencyParameterSensitivitySerializer.Proxy) = CurrencyParameterSensitivity.of( - (proxy as Proxy).marketDataName, + proxy.marketDataName, proxy.parameterMetadata, proxy.currency, proxy.sensitivity) - override fun toProxy(obj: Any): Any = Proxy ((obj as CurrencyParameterSensitivity).currency, + override fun toProxy(obj: CurrencyParameterSensitivity) = Proxy((obj as CurrencyParameterSensitivity).currency, obj.marketDataName, obj.parameterMetadata, obj.sensitivity) } diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencySerializer.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencySerializer.kt index 19f4de4195..f3b5534459 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencySerializer.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/CurrencySerializer.kt @@ -8,13 +8,13 @@ import java.lang.reflect.Type @CordaCustomSerializer @Suppress("UNUSED") -class CurrencySerializer : SerializationCustomSerializer { +class CurrencySerializer : SerializationCustomSerializer { @CordaCustomSerializerProxy data class Proxy(val currency: String) override val type: Type get() = Currency::class.java override val ptype: Type get() = Proxy::class.java - override fun fromProxy(proxy: Any): Any = Currency.parse((proxy as Proxy).currency) - override fun toProxy(obj: Any): Any = Proxy((obj as Currency).toString()) + override fun fromProxy(proxy: Proxy) = Currency.parse(proxy.currency) + override fun toProxy(obj: Currency) = Proxy(obj.toString()) } diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/DoubleArraySerializer.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/DoubleArraySerializer.kt index e429fc9d10..d9ad8e2c10 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/DoubleArraySerializer.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/DoubleArraySerializer.kt @@ -8,13 +8,13 @@ import java.lang.reflect.Type @CordaCustomSerializer @Suppress("UNUSED") -class DoubleArraySerializer : SerializationCustomSerializer { +class DoubleArraySerializer : SerializationCustomSerializer { @CordaCustomSerializerProxy data class Proxy(val amount: kotlin.DoubleArray) override val type: Type get() = DoubleArray::class.java override val ptype: Type get() = Proxy::class.java - override fun fromProxy(proxy: Any): Any = DoubleArray.copyOf((proxy as Proxy).amount) - override fun toProxy(obj: Any): Any = Proxy((obj as DoubleArray).toArray()) + override fun fromProxy(proxy: Proxy) = DoubleArray.copyOf(proxy.amount) + override fun toProxy(obj: DoubleArray) = Proxy(obj.toArray()) } diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/MultiCurrencyAmountSerializer.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/MultiCurrencyAmountSerializer.kt index fed97f7358..2df9ca801e 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/MultiCurrencyAmountSerializer.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/MultiCurrencyAmountSerializer.kt @@ -7,12 +7,13 @@ import java.lang.reflect.Type @CordaCustomSerializer @Suppress("UNUSED") -class MultiCurrencyAmountSerializer : SerializationCustomSerializer { +class MultiCurrencyAmountSerializer : + SerializationCustomSerializer { @CordaCustomSerializerProxy data class Proxy(val curencies : Map) - override fun toProxy(obj: Any): Any = Proxy((obj as MultiCurrencyAmount).toMap()) - override fun fromProxy(proxy: Any): Any = MultiCurrencyAmount.of((proxy as Proxy).curencies) + override fun toProxy(obj: MultiCurrencyAmount) = Proxy(obj.toMap()) + override fun fromProxy(proxy: Proxy) = MultiCurrencyAmount.of(proxy.curencies) override val type: Type get() = MultiCurrencyAmount::class.java override val ptype: Type get() = Proxy::class.java diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorDateParameterMetadataSerializer.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorDateParameterMetadataSerializer.kt index 84aac96da8..9814dbbf3f 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorDateParameterMetadataSerializer.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorDateParameterMetadataSerializer.kt @@ -8,16 +8,15 @@ import java.time.LocalDate @CordaCustomSerializer @Suppress("UNUSED") -class TenorDateParameterMetadataSerializer : SerializationCustomSerializer { +class TenorDateParameterMetadataSerializer : + SerializationCustomSerializer { @CordaCustomSerializerProxy data class Proxy(val tenor: Tenor, val date: LocalDate, val identifier: Tenor, val label: String) override val type: Type get() = TenorDateParameterMetadata::class.java override val ptype: Type get() = Proxy::class.java - override fun toProxy(obj: Any): Any = Proxy( - (obj as TenorDateParameterMetadata).tenor, obj.date, obj.identifier, obj.label) - override fun fromProxy(proxy: Any): Any = TenorDateParameterMetadata.of( - (proxy as Proxy).date, proxy.tenor, proxy.label) + override fun toProxy(obj: TenorDateParameterMetadata) = Proxy(obj.tenor, obj.date, obj.identifier, obj.label) + override fun fromProxy(proxy: Proxy) = TenorDateParameterMetadata.of(proxy.date, proxy.tenor, proxy.label) } diff --git a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorSerializer.kt b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorSerializer.kt index 8fc397ee34..f798a289fe 100644 --- a/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorSerializer.kt +++ b/samples/simm-valuation-demo/src/main/kotlin/net/corda/vega/plugin/customserializers/TenorSerializer.kt @@ -7,15 +7,13 @@ import java.time.Period @CordaCustomSerializer @Suppress("UNUSED") -class TenorSerializer : SerializationCustomSerializer { +class TenorSerializer : SerializationCustomSerializer { @CordaCustomSerializerProxy data class Proxy(val years: Int, val months: Int, val days: Int, val name: String) override val type: Type get() = Tenor::class.java override val ptype: Type get() = Proxy::class.java - override fun toProxy(obj: Any): Any = Proxy( - (obj as Tenor).period.years, obj.period.months, obj.period.days, obj.toString()) - - override fun fromProxy(proxy: Any): Any = Tenor.of (Period.of((proxy as Proxy).years, proxy.months, proxy.days)) + override fun toProxy(obj: Tenor) = Proxy(obj.period.years, obj.period.months, obj.period.days, obj.toString()) + override fun fromProxy(proxy: Proxy) = Tenor.of (Period.of(proxy.years, proxy.months, proxy.days)) }