mirror of
https://github.com/corda/corda.git
synced 2025-01-29 15:43:55 +00:00
Adding BigInteger serialization support (#2804)
* Adding BigInteger serialization support * Addressing review comments
This commit is contained in:
parent
88c5ab8870
commit
15e4449b38
@ -13,6 +13,10 @@ from the previous milestone release.
|
||||
|
||||
* Introduced a placeholder for custom properties within ``node.conf``; the property key is "custom".
|
||||
|
||||
* java.math.BigInteger serialization support added.
|
||||
|
||||
* java.security.cert.CRLReason added to the default Whitelist.
|
||||
|
||||
.. _changelog_v3:
|
||||
|
||||
Version 3.0
|
||||
|
@ -53,6 +53,7 @@ abstract class AbstractAMQPSerializationScheme(val cordappLoader: List<Cordapp>)
|
||||
register(net.corda.nodeapi.internal.serialization.amqp.custom.PrivateKeySerializer)
|
||||
register(net.corda.nodeapi.internal.serialization.amqp.custom.ThrowableSerializer(this))
|
||||
register(net.corda.nodeapi.internal.serialization.amqp.custom.BigDecimalSerializer)
|
||||
register(net.corda.nodeapi.internal.serialization.amqp.custom.BigIntegerSerializer)
|
||||
register(net.corda.nodeapi.internal.serialization.amqp.custom.CurrencySerializer)
|
||||
register(net.corda.nodeapi.internal.serialization.amqp.custom.OpaqueBytesSubSequenceSerializer(this))
|
||||
register(net.corda.nodeapi.internal.serialization.amqp.custom.InstantSerializer(this))
|
||||
|
@ -0,0 +1,11 @@
|
||||
package net.corda.nodeapi.internal.serialization.amqp.custom
|
||||
|
||||
import net.corda.nodeapi.internal.serialization.amqp.CustomSerializer
|
||||
import java.math.BigInteger
|
||||
|
||||
/**
|
||||
* A serializer for [BigInteger], utilising the string based helper. [BigInteger] seems to have no import/export
|
||||
* features that are precision independent other than via a string. The format of the string is discussed in the
|
||||
* documentation for [BigInteger.toString].
|
||||
*/
|
||||
object BigIntegerSerializer : CustomSerializer.ToString<BigInteger>(BigInteger::class.java)
|
@ -40,6 +40,7 @@ import java.io.ByteArrayInputStream
|
||||
import java.io.IOException
|
||||
import java.io.NotSerializableException
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.time.*
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.util.*
|
||||
@ -976,6 +977,21 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
assertEquals(objCopy.a, objCopy.b)
|
||||
}
|
||||
|
||||
data class BigIntegers(val a: BigInteger, val b: BigInteger)
|
||||
|
||||
@Test
|
||||
fun `test BigInteger custom serializer`() {
|
||||
val factory = SerializerFactory(AllWhitelist, ClassLoader.getSystemClassLoader())
|
||||
factory.register(net.corda.nodeapi.internal.serialization.amqp.custom.BigIntegerSerializer)
|
||||
|
||||
val factory2 = SerializerFactory(AllWhitelist, ClassLoader.getSystemClassLoader())
|
||||
factory2.register(net.corda.nodeapi.internal.serialization.amqp.custom.BigIntegerSerializer)
|
||||
|
||||
val obj = BigIntegers(BigInteger.TEN, BigInteger.TEN)
|
||||
val objCopy = serdes(obj, factory, factory2)
|
||||
assertEquals(objCopy.a, objCopy.b)
|
||||
}
|
||||
|
||||
data class ByteArrays(val a: ByteArray, val b: ByteArray)
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user