diff --git a/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt b/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt index d360997fbf..af64d56aa4 100644 --- a/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt +++ b/client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt @@ -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() { override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): OpaqueBytes { - return OpaqueBytes(parser.binaryValue) + return OpaqueBytes(parser.text?.toByteArray(UTF_8) ?: parser.binaryValue) } } diff --git a/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt b/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt index 4283523a33..86c50a4160 100644 --- a/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt +++ b/client/jackson/src/test/kotlin/net/corda/client/jackson/JacksonSupportTest.kt @@ -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(opaqueBytes) assertThat(json.binaryValue()).isEqualTo(opaqueBytes.bytes) assertThat(json.asText()).isEqualTo(opaqueBytes.bytes.toBase64()) - assertThat(mapper.convertValue(json)).isEqualTo(opaqueBytes) + } + + @Test + fun `OpaqueBytes deserialization`() { + assertThat(mapper.convertValue(TextNode("1234"))).isEqualTo(OpaqueBytes("1234".toByteArray(UTF_8))) + assertThat(mapper.convertValue(BinaryNode(byteArrayOf(1, 2, 3, 4)))).isEqualTo(OpaqueBytes.of(1, 2, 3, 4)) } @Test diff --git a/docs/source/shell.rst b/docs/source/shell.rst index b03bf70601..a83c018655 100644 --- a/docs/source/shell.rst +++ b/docs/source/shell.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~