avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yang <teddyyyy...@gmail.com>
Subject Re: space " " produced in jsonencoder ?
Date Tue, 04 Oct 2011 18:41:50 GMT
created https://issues.apache.org/jira/browse/AVRO-905

Thanks
Yang

On Tue, Oct 4, 2011 at 11:37 AM, Doug Cutting <cutting@apache.org> wrote:
> 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