You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Brandon Forehand (JIRA)" <ji...@apache.org> on 2014/07/17 23:46:06 UTC
[jira] [Updated] (AVRO-1546) Make GenericData.Record.toString
consistent
[ https://issues.apache.org/jira/browse/AVRO-1546?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Brandon Forehand updated AVRO-1546:
-----------------------------------
Attachment: unescape_slash.patch
> Make GenericData.Record.toString consistent
> -------------------------------------------
>
> Key: AVRO-1546
> URL: https://issues.apache.org/jira/browse/AVRO-1546
> Project: Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.7.6
> Reporter: Brandon Forehand
> Priority: Minor
> Attachments: unescape_slash.patch
>
>
> Currently, if you have a GenericData.Record and call toString on it, it provides a JSON representation of this record type. However, if the record contains a string that contains a literal forward slash, the forward slash gets escaped by the writeEscapedString function which means that the string representation is not equivalent after round-tripping the value.
> According to the [ECMA standard for JSON|http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf], forward slash can be escaped; however, the values {{"\u002F"}}, {{"\u002f"}}, {{"\/"}}, and {{"/"}} are all the same. Thus, it seems to be preferred to produce the shortest version. This is the way that Jackson works as well:
> {code}
> JsonMapper mapper = new JsonMapper();
> JsonFactory factory = new JsonFactory();
> JsonNode node = mapper.readTree(factory.createJsonParser("\"/path/\""));
> mapper.readValue(node, String.class) // => "/path/"
> mapper.readTree(factory.createJsonParser("\"\/path\/\"")
> mapper.readValue(node, String.class) // => "/path/"
> {code}
> This shows that whether or not the input is escaped that the JSON output produced in both cases is the unescaped forward slash.
--
This message was sent by Atlassian JIRA
(v6.2#6252)