avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: space " " produced in jsonencoder ?
Date Tue, 04 Oct 2011 18:37:17 GMT
On 10/04/2011 11:25 AM, Yang wrote:
> let me try out the MinimalPrettyPrinter,

Here's a patch that works for me:

Index: lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
===================================================================
--- lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
(revision 1178534)
+++ 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;
   }

   /**

Mime
View raw message