mirror of
https://github.com/corda/corda.git
synced 2025-05-03 01:03:18 +00:00
ENT-3440 Allow custom serializers that extend CordaThrowable.
This commit is contained in:
parent
17e7cd3abc
commit
864efe38d1
@ -1,5 +1,6 @@
|
|||||||
package net.corda.serialization.internal.amqp
|
package net.corda.serialization.internal.amqp
|
||||||
|
|
||||||
|
import net.corda.core.CordaThrowable
|
||||||
import net.corda.core.internal.uncheckedCast
|
import net.corda.core.internal.uncheckedCast
|
||||||
import net.corda.core.serialization.CordaSerializable
|
import net.corda.core.serialization.CordaSerializable
|
||||||
import net.corda.core.utilities.contextLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
@ -156,6 +157,7 @@ class CachingCustomSerializerRegistry(
|
|||||||
|
|
||||||
private val Class<*>.isCustomSerializationForbidden: Boolean get() = when {
|
private val Class<*>.isCustomSerializationForbidden: Boolean get() = when {
|
||||||
AMQPTypeIdentifiers.isPrimitive(this) -> true
|
AMQPTypeIdentifiers.isPrimitive(this) -> true
|
||||||
|
isSubClassOf(CordaThrowable::class.java) -> false
|
||||||
isAnnotationPresent(CordaSerializable::class.java) -> true
|
isAnnotationPresent(CordaSerializable::class.java) -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package net.corda.serialization.internal.amqp
|
package net.corda.serialization.internal.amqp
|
||||||
|
|
||||||
|
import net.corda.core.CordaException
|
||||||
import net.corda.core.serialization.CordaSerializable
|
import net.corda.core.serialization.CordaSerializable
|
||||||
import net.corda.core.serialization.SerializationContext
|
import net.corda.core.serialization.SerializationContext
|
||||||
import net.corda.finance.contracts.asset.Cash
|
import net.corda.finance.contracts.asset.Cash
|
||||||
import org.apache.qpid.proton.amqp.Symbol
|
import org.apache.qpid.proton.amqp.Symbol
|
||||||
import org.apache.qpid.proton.codec.Data
|
import org.apache.qpid.proton.codec.Data
|
||||||
import org.junit.Ignore
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
import java.math.BigDecimal
|
|
||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
import kotlin.test.assertSame
|
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
|
@Test
|
||||||
fun `two custom serializers cannot register to serialize the same type`() {
|
fun `two custom serializers cannot register to serialize the same type`() {
|
||||||
val weSerializeCash = TestCustomSerializer("a") { type -> type == Cash::class.java }
|
val weSerializeCash = TestCustomSerializer("a") { type -> type == Cash::class.java }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user