From a5d5e0d47600c7fe2d484c421a6988a08ec1fde7 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 19 Aug 2019 18:12:04 +0100 Subject: [PATCH] Allow custom serialization for all subclasses of a configurable set of classes. --- .../internal/amqp/CustomSerializerRegistry.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistry.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistry.kt index 8397fe8018..d0e8700e08 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistry.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/CustomSerializerRegistry.kt @@ -57,8 +57,10 @@ interface CustomSerializerRegistry { } class CachingCustomSerializerRegistry( - private val descriptorBasedSerializerRegistry: DescriptorBasedSerializerRegistry) - : CustomSerializerRegistry { + private val descriptorBasedSerializerRegistry: DescriptorBasedSerializerRegistry, + private val allowedFor: Set> +) : CustomSerializerRegistry { + constructor(descriptorBasedSerializerRegistry: DescriptorBasedSerializerRegistry) : this(descriptorBasedSerializerRegistry, emptySet()) companion object { val logger = contextLogger() @@ -185,6 +187,7 @@ class CachingCustomSerializerRegistry( private val Class<*>.isCustomSerializationForbidden: Boolean get() = when { AMQPTypeIdentifiers.isPrimitive(this) -> true isSubClassOf(CordaThrowable::class.java) -> false + allowedFor.any { it.isAssignableFrom(this) } -> false isAnnotationPresent(CordaSerializable::class.java) -> true else -> false }