Avro
  1. Avro
  2. AVRO-905

make default separator in jsonEncoder to be "\n" instead of " "

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.6.0
    • Component/s: java
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      from mailing list:

      if I do

      writer = new SpecificDatumWriter<SpecificRecord>(schema);
      encoder = EncoderFactory.get().jsonEncoder(schema, ostream);

      writer.write(my_specific_record, encoder);
      writer.write(my_specific_record.encoder);

      it adds a space " " between the 2 records, I guess for separation.
      is it possible to remove that? or changing that to "\n" is much better

      Doug said:
      ......
      or you could pass a JsonGenerator to EncoderFactory#jsonEncoder a
      MinimalPrettyPrinter whose rootValueSeparator is set to "\n".

      http://jackson.codehaus.org/1.8.4/javadoc/org/codehaus/jackson/util/MinimalPrettyPrinter.html

      +++ lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
      (working copy)
      @@ -31,6 +31,7 @@
      import org.codehaus.jackson.JsonEncoding;
      import org.codehaus.jackson.JsonFactory;
      import org.codehaus.jackson.JsonGenerator;
      +import org.codehaus.jackson.util.MinimalPrettyPrinter;

      /** An

      {@link Encoder}

      for Avro's JSON data encoding.

      • </p>
        @@ -67,11 +68,17 @@
        }
        }

      + // by default, one object per line
      private static JsonGenerator getJsonGenerator(OutputStream out)
      throws IOException

      { if (null == out) throw new NullPointerException("OutputStream cannot be null"); - return new JsonFactory().createJsonGenerator(out, JsonEncoding.UTF8); + JsonGenerator g + = new JsonFactory().createJsonGenerator(out, JsonEncoding.UTF8); + MinimalPrettyPrinter pp = new MinimalPrettyPrinter(); + pp.setRootValueSeparator("\n"); + g.setPrettyPrinter(pp); + return g; }
      1. AVRO-905.patch
        1 kB
        Doug Cutting
      2. AVRO-905.patch
        2 kB
        Doug Cutting
      3. AVRO-905.patch
        3 kB
        Doug Cutting

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Doug Cutting
            Reporter:
            Yang Yang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development