mirror of
https://github.com/corda/corda.git
synced 2025-01-18 02:39:51 +00:00
Added back support for parsing OpaqueBytes as UTF-8 strings in JacksonSupport (#3240)
This commit is contained in:
parent
a63e08d94c
commit
d772bc8b7f
@ -39,6 +39,7 @@ import net.corda.core.utilities.toBase58String
|
||||
import org.bouncycastle.asn1.x509.KeyPurposeId
|
||||
import java.lang.reflect.Modifier
|
||||
import java.math.BigDecimal
|
||||
import java.nio.charset.StandardCharsets.UTF_8
|
||||
import java.security.PublicKey
|
||||
import java.security.cert.CertPath
|
||||
import java.security.cert.CertificateFactory
|
||||
@ -416,7 +417,7 @@ object JacksonSupport {
|
||||
@Deprecated("This is an internal class, do not use")
|
||||
object OpaqueBytesDeserializer : JsonDeserializer<OpaqueBytes>() {
|
||||
override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): OpaqueBytes {
|
||||
return OpaqueBytes(parser.binaryValue)
|
||||
return OpaqueBytes(parser.text?.toByteArray(UTF_8) ?: parser.binaryValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
import org.junit.runners.Parameterized.Parameters
|
||||
import java.math.BigInteger
|
||||
import java.nio.charset.StandardCharsets.*
|
||||
import java.security.PublicKey
|
||||
import java.security.cert.CertPath
|
||||
import java.security.cert.X509Certificate
|
||||
@ -103,12 +104,17 @@ class JacksonSupportTest(@Suppress("unused") private val name: String, factory:
|
||||
}
|
||||
|
||||
@Test
|
||||
fun OpaqueBytes() {
|
||||
fun `OpaqueBytes serialization`() {
|
||||
val opaqueBytes = OpaqueBytes(secureRandomBytes(128))
|
||||
val json = mapper.valueToTree<BinaryNode>(opaqueBytes)
|
||||
assertThat(json.binaryValue()).isEqualTo(opaqueBytes.bytes)
|
||||
assertThat(json.asText()).isEqualTo(opaqueBytes.bytes.toBase64())
|
||||
assertThat(mapper.convertValue<OpaqueBytes>(json)).isEqualTo(opaqueBytes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OpaqueBytes deserialization`() {
|
||||
assertThat(mapper.convertValue<OpaqueBytes>(TextNode("1234"))).isEqualTo(OpaqueBytes("1234".toByteArray(UTF_8)))
|
||||
assertThat(mapper.convertValue<OpaqueBytes>(BinaryNode(byteArrayOf(1, 2, 3, 4)))).isEqualTo(OpaqueBytes.of(1, 2, 3, 4))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -267,9 +267,9 @@ SecureHash
|
||||
~~~~~~~~~~
|
||||
A parameter of type ``SecureHash`` can be written as a hexadecimal string: ``F69A7626ACC27042FEEAE187E6BFF4CE666E6F318DC2B32BE9FAF87DF687930C``
|
||||
|
||||
OpaqueBytes and SerializedBytes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
A parameter of type ``OpaqueBytes`` can be provided as a string in Base64.
|
||||
OpaqueBytes
|
||||
~~~~~~~~~~~
|
||||
A parameter of type ``OpaqueBytes`` can be provided as a UTF-8 string.
|
||||
|
||||
PublicKey and CompositeKey
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
Loading…
Reference in New Issue
Block a user