[ https://issues.apache.org/jira/browse/KAFKA-14794?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
José Armando García Sancio resolved KAFKA-14794. ------------------------------------------------ Fix Version/s: 3.5.0 Resolution: Fixed > Unable to deserialize base64 JSON strings > ------------------------------------------ > > Key: KAFKA-14794 > URL: https://issues.apache.org/jira/browse/KAFKA-14794 > Project: Kafka > Issue Type: Bug > Reporter: José Armando García Sancio > Assignee: José Armando García Sancio > Priority: Major > Fix For: 3.5.0 > > > h1. Problem > The following test fails: > {code:java} > @Test > public void testBinaryNode() throws IOException { > byte[] expected = new byte[] {5, 2, 9, 4, 1, 8, 7, 0, 3, 6}; > StringWriter writer = new StringWriter(); > ObjectMapper mapper = new ObjectMapper(); > mapper.writeTree(mapper.createGenerator(writer), new > BinaryNode(expected)); > JsonNode binaryNode = mapper.readTree(writer.toString()); > assertTrue(binaryNode.isTextual(), binaryNode.toString()); > byte[] actual = MessageUtil.jsonNodeToBinary(binaryNode, "Test base64 > JSON string"); > assertEquals(expected, actual); > } > {code} > with the following error: > {code:java} > Gradle Test Run :clients:test > Gradle Test Executor 20 > MessageUtilTest > > testBinaryNode() FAILED > java.lang.RuntimeException: Test base64 JSON string: expected > Base64-encoded binary data. > at > org.apache.kafka.common.protocol.MessageUtil.jsonNodeToBinary(MessageUtil.java:165) > at > org.apache.kafka.common.protocol.MessageUtilTest.testBinaryNode(MessageUtilTest.java:102) > {code} > The reason for the failure is because FasterXML Jackson deserializes base64 > JSON strings to a TextNode not to a BinaryNode. > h1. Solution > The method {{MessageUtil::jsonNodeToBinary}} should not assume that the input > {{JsonNode}} is always a {{{}BinaryNode{}}}. It should also support decoding > {{{}TextNode{}}}. > {{JsonNode::binaryValue}} is supported by both {{BinaryNode}} and > {{{}TextNode{}}}. -- This message was sent by Atlassian Jira (v8.20.10#820010)