Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1546

Make GenericData.Record.toString consistent

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.7.6
    • 1.7.7
    • java
    • None

    Description

      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, forward slash can be escaped; however, the values "\u002F", "\u002f", "\/", and "/" are all the same. Thus, it seems preferable to produce the shortest version. This is the way that Jackson works as well:

      JsonMapper mapper = new JsonMapper();
      JsonFactory factory = new JsonFactory();
      JsonNode node = mapper.readTree(factory.createJsonParser("\"/path/\""));
      mapper.readValue(node, String.class); // => "/path/"
      
      node = mapper.readTree(factory.createJsonParser("\"\/path\/\"");
      mapper.readValue(node, String.class); // => "/path/"
      

      This shows that whether or not the input is escaped that the JSON output produced in both cases is the unescaped forward slash.

      Attachments

        1. unescape_slash.patch
          2 kB
          Brandon Forehand
        2. unescape_slash2.patch
          1 kB
          Brandon Forehand

        Activity

          People

            b4hand Brandon Forehand
            b4hand Brandon Forehand
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: