avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [avro] 01/04: Option to remove the namespace from the JSON encoder
Date Fri, 16 Aug 2019 18:37:54 GMT
This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 080152eeb732a888dc6edd8e03073addeae7c2b0
Author: Juan Sebastián Urrego Escobar <juancho088@gmail.com>
AuthorDate: Wed Apr 24 11:00:09 2019 +0200

    Option to remove the namespace from the JSON encoder
---
 .../avro/src/main/java/org/apache/avro/io/JsonEncoder.java   | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
index 88767d8..f62c9c4 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
@@ -49,6 +49,8 @@ public class JsonEncoder extends ParsingEncoder implements Parser.ActionHandler
   private static final String LINE_SEPARATOR = System.getProperty("line.separator");
   final Parser parser;
   private JsonGenerator out;
+  private boolean includeNamespace = true;
+
   /**
    * Has anything been written into the collections?
    */
@@ -97,6 +99,14 @@ public class JsonEncoder extends ParsingEncoder implements Parser.ActionHandler
     return g;
   }
 
+  public boolean isIncludeNamespace() {
+    return includeNamespace;
+  }
+
+  public void setIncludeNamespace(final boolean includeNamespace) {
+    this.includeNamespace = includeNamespace;
+  }
+
   /**
    * Reconfigures this JsonEncoder to use the output stream provided.
    * <p/>
@@ -283,7 +293,7 @@ public class JsonEncoder extends ParsingEncoder implements Parser.ActionHandler
     parser.advance(Symbol.UNION);
     Symbol.Alternative top = (Symbol.Alternative) parser.popSymbol();
     Symbol symbol = top.getSymbol(unionIndex);
-    if (symbol != Symbol.NULL) {
+    if (symbol != Symbol.NULL && includeNamespace) {
       out.writeStartObject();
       out.writeFieldName(top.getLabel(unionIndex));
       parser.pushSymbol(Symbol.UNION_END);


Mime
View raw message