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

Ryan Skraba commented on AVRO-3061:
-----------------------------------

Yes, it does "look like" JSON, and it's a frequent source of issues in our 
company :/  I'm surprised that there isn't another Jira on this!  It's not even 
guaranteed to be valid JSON much less valid "Avro-compliant" JSON encoding (if 
I remember correctly, binary data isn't escaped quite right).

I would _almost_ prefer that we break the toString representation entirely so 
that it doesn't even look like JSON.  There's quite a few reasons why 
developers should be [strongly discouraged from parsing 
toString|https://conscientiousprogrammer.com/blog/2013/12/23/tostring-considered-harmful-part-1/]
 output.  

The issue with fixing it now, of course, is that it would break developers that 
are relying on the "Kinda-Avro-ish JSON" encoding that the Java toString 
provides (despite it being potentially fragile and often not compatible with 
JsonDecoder, notably around UNIONs).  They'd need some sort of heads-up and 
"escape route" when migrating to a version that changes the toString for any 
reason.  A system property, perhaps?

It's worth discussing, precisely because this comes up so often!

> toString implementation on avro objects emits confusing json
> ------------------------------------------------------------
>
>                 Key: AVRO-3061
>                 URL: https://issues.apache.org/jira/browse/AVRO-3061
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.10.1
>            Reporter: radai rosenblatt
>            Priority: Major
>
> toString() for both specific and generic records emits what looks to be avro 
> json format, but isnt.
>  
> its close enough for new users to try using toString() output where avro json 
> is expected.
>  
> it would be better if the toString() implementation was changed to use a 
> proper JsonEncoder so that the output would actually be valid avro json. it 
> would also result in less code overall



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to