avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yang Yang (Created) (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AVRO-905) make default separator in jsonEncoder to be "\n" instead of " "
Date Tue, 04 Oct 2011 18:41:34 GMT
make default separator in jsonEncoder to be "\n" instead of " "

                 Key: AVRO-905
                 URL: https://issues.apache.org/jira/browse/AVRO-905
             Project: Avro
          Issue Type: Improvement
            Reporter: Yang Yang
            Priority: Minor

from mailing list:

if I do

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

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".


+++ 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;

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message