[ 
https://issues.apache.org/jira/browse/AVRO-1584?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15057042#comment-15057042
 ] 

Ryan Blue commented on AVRO-1584:
---------------------------------

Thanks for the context, Doug.

I agree that we shouldn't change the specified JSON encoding or toString 
behavior. I think we have some flexibility with toString, since it was intended 
for debugging (so it isn't used to encode default values) and doesn't encode 
either bytes or fixed as expected. For bytes, an extra object layer is added 
and fixed is encoded as an array of integers. I think that makes it unlikely 
that anyone would use it to serialize data as JSON, but I have no problem being 
cautious and not breaking anything unless we have a plan for what toString 
should produce.

I'm attaching a patch that uses the fix from AVRO-713 to fix just the escape 
problem. It also adds tests to validate the current behavior of toString for 
bytes and fixed.

> Json output doesn't generate base64 for byte arrays
> ---------------------------------------------------
>
>                 Key: AVRO-1584
>                 URL: https://issues.apache.org/jira/browse/AVRO-1584
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.7
>         Environment: Pure java.
>            Reporter: Christophe Lorenz
>         Attachments: AVRO-1584-Jackson-Base64-Default-Variant.patch, 
> AVRO-1584.patch
>
>
> The Json output of java generated code doesn't correctly encode byte arrays.
> Using this simple schema : 
> {"namespace": "example.avro",
>  "type": "record",
>  "name": "ByteArrayEncoding",
>  "fields": [     {"name": "data", "type": "bytes"} ]
> }
> The toString()  
>       System.out.println(new ByteArrayEncoding(ByteBuffer.wrap(new 
> byte[]{0,31,65,66,67,(byte)255,(byte)182})));
> Returns raw bytes to string in the json :
> {"data": {"bytes": "  ABC??"}}
> As a byte array is not tied to be a valid string, it should be converted back 
> and forth to Base64 like other Json implementations : 
> {"data": {"bytes": "AB9BQkP/tg=="}}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to