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

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

David, you're right. There are actually two different code paths to transform a 
record to JSON. The encoder, and the {{GenericData#toString(Object)}} path. I'm 
not entirely sure what the history is there. Maybe [~cutting] or [~tomwhite] 
knows?

I don't think the output of toString here is covered by the spec since it 
doesn't appear to implement the spec, as you can see with the addition of the 
extra object layer with a "bytes" key. I'm a little reluctant to change what 
this currently produces, since the method claims to produce JSON and it is 
probably used by someone to produce data files, but the 1.8.0 release is coming 
up so we can.

Your patch adds a method for converting bytes to base64. Is it possible to use 
a library method there instead of adding an implementation to maintain? Also, 
could you apply a similar change to how Fixed is handled? I think we should 
probably fix both at the same time.

> 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.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