[
https://issues.apache.org/jira/browse/AVRO-4234?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Maciej Noszczyński updated AVRO-4234:
-------------------------------------
Summary: [Java] Byte array JSON serialization in IdlUtils doesn't work at
all (was: Byte array JSON serialization in IdlUtils doesn't work at all)
> [Java] Byte array JSON serialization in IdlUtils doesn't work at all
> --------------------------------------------------------------------
>
> Key: AVRO-4234
> URL: https://issues.apache.org/jira/browse/AVRO-4234
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.12.1
> Reporter: Maciej Noszczyński
> Priority: Major
>
> The IdlUtils class used to generate Avro IDL text from e.g. a Schema object,
> doesn't work correctly for byte array (default) values. No string literal
> gets emitted in this case.
> The problematic code:
> {code:java}
> module.addSerializer(new StdSerializer<byte[]>(byte[].class) {
> @Override
> public void serialize(byte[] value, JsonGenerator gen,
> SerializerProvider provider) throws IOException {
> MAPPER.writeValueAsString(new String(value,
> StandardCharsets.ISO_8859_1));
> }
> });
> {code}
> Here, the `MAPPER` gets called instead of `gen`, (so without the side effect
> of actually storing the generated text in the current ObjectMapper call
> output), and the result of the call gets immediately discarded.
> Corrected:
> {code:java}
> module.addSerializer(new StdSerializer<byte[]>(byte[].class) {
> @Override
> public void serialize(byte[] value, JsonGenerator gen,
> SerializerProvider provider) throws IOException {
> gen.writeString(new String(value, StandardCharsets.ISO_8859_1));
> }
> });
> {code}
> There is a test called `IdlUtilsTest`, but looking at the contents, it is not
> possible, that it runs successfully with the current code. The build still
> works, which is mysterious. Is it possible, that the test is disabled for
> some reason or even by mistake?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)