Avro
  1. Avro
  2. AVRO-713

GenericRecord.toString can produce invalid JSON

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4.1
    • Fix Version/s: 1.5.0
    • Component/s: java
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      The GenericData.toString method can produce invalid JSON. The problem is that enums are printed without quotes, as in

      {"emum_field":a}

      instead of

      {"enum_field":"a"}

        Issue Links

          Activity

          Hide
          Jay Kreps added a comment -

          Here is a patch that fixes the enum issue. It also includes proper escaping of JSON strings (i.e. so if the string contains a quote the json string isn't prematurely terminated. The escaping code is adapted from http://code.google.com/p/json-simple/source/browse/trunk/src/org/json/simple/JSONValue.java#227.

          Copying the escaping code to write directly to the StringBuilder seems better than using Jackson, since I think with Jackson we would have to instantiate a bunch of objects and double-copy the string.

          Show
          Jay Kreps added a comment - Here is a patch that fixes the enum issue. It also includes proper escaping of JSON strings (i.e. so if the string contains a quote the json string isn't prematurely terminated. The escaping code is adapted from http://code.google.com/p/json-simple/source/browse/trunk/src/org/json/simple/JSONValue.java#227 . Copying the escaping code to write directly to the StringBuilder seems better than using Jackson, since I think with Jackson we would have to instantiate a bunch of objects and double-copy the string.
          Hide
          Doug Cutting added a comment -

          I committed this. Thanks, Jay!

          Show
          Doug Cutting added a comment - I committed this. Thanks, Jay!

            People

            • Assignee:
              Jay Kreps
              Reporter:
              Jay Kreps
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development