ENT-3440 Allow custom serializers that extend CordaThrowable.

This commit is contained in:
josecoll 2019-03-29 11:30:46 +00:00
parent 17e7cd3abc
commit 864efe38d1
2 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package net.corda.serialization.internal.amqp
import net.corda.core.CordaThrowable
import net.corda.core.internal.uncheckedCast
import net.corda.core.serialization.CordaSerializable
import net.corda.core.utilities.contextLogger
@ -156,6 +157,7 @@ class CachingCustomSerializerRegistry(
private val Class<*>.isCustomSerializationForbidden: Boolean get() = when {
AMQPTypeIdentifiers.isPrimitive(this) -> true
isSubClassOf(CordaThrowable::class.java) -> false
isAnnotationPresent(CordaSerializable::class.java) -> true
else -> false
}

View File

@ -1,14 +1,13 @@
package net.corda.serialization.internal.amqp
import net.corda.core.CordaException
import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.SerializationContext
import net.corda.finance.contracts.asset.Cash
import org.apache.qpid.proton.amqp.Symbol
import org.apache.qpid.proton.codec.Data
import org.junit.Ignore
import org.junit.Test
import java.lang.reflect.Type
import java.math.BigDecimal
import kotlin.test.assertFailsWith
import kotlin.test.assertSame
@ -56,6 +55,19 @@ class CustomSerializerRegistryTests {
}
}
@Test
fun `exception types can have custom serializers`() {
@CordaSerializable
class MyCustomException : CordaException("Custom exception annotated with @CordaSerializable")
val customExceptionSerializer = TestCustomSerializer("a") { type -> type == MyCustomException::class.java }
unit.register(customExceptionSerializer)
assertSame(
customExceptionSerializer,
unit.find(MyCustomException::class.java))
}
@Test
fun `two custom serializers cannot register to serialize the same type`() {
val weSerializeCash = TestCustomSerializer("a") { type -> type == Cash::class.java }