diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeModellingFingerPrinter.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeModellingFingerPrinter.kt index c0db392d88..b0314bbc2a 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeModellingFingerPrinter.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/model/TypeModellingFingerPrinter.kt @@ -139,8 +139,7 @@ private class FingerPrintingState( is LocalTypeInformation.Abstract -> fingerprintAbstract(type) is LocalTypeInformation.Singleton -> fingerprintName(type) is LocalTypeInformation.Composable -> fingerprintComposable(type) - is LocalTypeInformation.NonComposable -> throw NotSerializableException( - "Attempted to fingerprint non-composable type ${type.typeIdentifier.prettyPrint(false)}") + is LocalTypeInformation.NonComposable -> fingerprintNonComposable(type) } } @@ -176,6 +175,14 @@ private class FingerPrintingState( fingerprintTypeParameters(type.typeParameters) } + private fun fingerprintNonComposable(type: LocalTypeInformation.NonComposable) = + fingerprintWithCustomSerializerOrElse(type) { + fingerprintName(type) + fingerprintProperties(type.properties) + fingerprintInterfaces(type.interfaces) + fingerprintTypeParameters(type.typeParameters) + } + private fun fingerprintComposable(type: LocalTypeInformation.Composable) = fingerprintWithCustomSerializerOrElse(type) { fingerprintName(type) diff --git a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/TypeModellingFingerPrinterTests.kt b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/TypeModellingFingerPrinterTests.kt index 79f931571a..0369363bb3 100644 --- a/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/TypeModellingFingerPrinterTests.kt +++ b/serialization/src/test/kotlin/net/corda/serialization/internal/amqp/TypeModellingFingerPrinterTests.kt @@ -1,9 +1,14 @@ package net.corda.serialization.internal.amqp +import net.corda.serialization.internal.AllWhitelist +import net.corda.serialization.internal.NotSerializable +import net.corda.serialization.internal.model.ConfigurableLocalTypeModel import net.corda.serialization.internal.model.LocalTypeInformation import net.corda.serialization.internal.model.TypeModellingFingerPrinter +import org.assertj.core.api.Assertions.assertThat import org.junit.Test import kotlin.test.assertNotEquals +import kotlin.test.assertTrue class TypeModellingFingerPrinterTests { @@ -19,4 +24,23 @@ class TypeModellingFingerPrinterTests { assertNotEquals(fingerprinter.fingerprint(objectType), fingerprinter.fingerprint(anyType)) } + + // Not serializable, because there is no readable property corresponding to the constructor parameter + class NonSerializable(a: String) + + class HasTypeParameter + data class SuppliesTypeParameter(val value: HasTypeParameter) + + // See https://r3-cev.atlassian.net/browse/CORDA-2848 + @Test + fun `can fingerprint type with non-serializable type parameter`() { + val typeModel = ConfigurableLocalTypeModel(WhitelistBasedTypeModelConfiguration(AllWhitelist, customRegistry)) + val typeInfo = typeModel.inspect(SuppliesTypeParameter::class.java) + + assertThat(typeInfo).isInstanceOf(LocalTypeInformation.Composable::class.java) + val propertyTypeInfo = typeInfo.propertiesOrEmptyMap["value"]?.type as LocalTypeInformation.Composable + assertThat(propertyTypeInfo.typeParameters[0]).isInstanceOf(LocalTypeInformation.NonComposable::class.java) + + fingerprinter.fingerprint(typeInfo) + } } \ No newline at end of file