Bug 1761: Fixed missing module name prefix for augmentations. 43/11043/6
authorTony Tkacik <ttkacik@cisco.com>
Thu, 11 Sep 2014 11:53:45 +0000 (13:53 +0200)
committerRobert Varga <rovarga@cisco.com>
Fri, 12 Sep 2014 19:45:48 +0000 (21:45 +0200)
Migration to more state tracking introduced regression
where module name prefix was left out for containers
and lists which were augmented, which was inconsistent
with case augmentations, which were serialized properly.

Draft draft-lhotka-netmod-yang-json-02 allows previous
behaviour (without module names for augmented items),
but that may cause changing textual representation
after conflicting augmentation is introduced,
so we opted to always report module name for top level
items of augmentation, which is also allowed from spec.

Change-Id: Icbb1b2aeed1a154a06e7f90f0dacc199a7df6bcc
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONNormalizedNodeStreamWriter.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONStreamWriterContext.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONStreamWriterListContext.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONStreamWriterNamedObjectContext.java

index 643e9de9ad041f9b2c4c3c02bf6e3d3317061295..8fcc596ab47ebe3e8e5d2ed86ecb00f8cc2d104e 100644 (file)
@@ -11,11 +11,9 @@ import com.google.common.base.CharMatcher;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.gson.stream.JsonWriter;
-
 import java.io.IOException;
 import java.io.Writer;
 import java.net.URI;
-
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -136,7 +134,7 @@ public class JSONNormalizedNodeStreamWriter implements NormalizedNodeStreamWrite
         final JSONCodec<Object> codec = codecs.codecFor(schema.getType());
 
         context.emittingChild(codecs.getSchemaContext(), writer, indent);
-        context.writeJsonIdentifier(codecs.getSchemaContext(), writer, name.getNodeType());
+        context.writeChildJsonIdentifier(codecs.getSchemaContext(), writer, name.getNodeType());
         writeValue(codec.serialize(value), codec.needQuotes());
     }
 
@@ -211,11 +209,12 @@ public class JSONNormalizedNodeStreamWriter implements NormalizedNodeStreamWrite
 
     @Override
     public void anyxmlNode(final NodeIdentifier name, final Object value) throws IOException {
+        @SuppressWarnings("unused")
         final AnyXmlSchemaNode schema = tracker.anyxmlNode(name);
         // FIXME: should have a codec based on this :)
 
         context.emittingChild(codecs.getSchemaContext(), writer, indent);
-        context.writeJsonIdentifier(codecs.getSchemaContext(), writer, name.getNodeType());
+        context.writeChildJsonIdentifier(codecs.getSchemaContext(), writer, name.getNodeType());
         writeValue(String.valueOf(value), true);
     }
 
index 1a5181a5789f2e81982348fc263623e0f7a7e049..a3ad80dfb3f28473b523f3b12c1a1cc335063715 100644 (file)
@@ -8,13 +8,10 @@
 package org.opendaylight.yangtools.yang.data.codec.gson;
 
 import com.google.common.base.Preconditions;
-
 import java.io.IOException;
 import java.io.Writer;
 import java.net.URI;
-
 import javax.annotation.Nonnull;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -50,7 +47,7 @@ abstract class JSONStreamWriterContext {
     }
 
     /**
-     * Write a JSON node identifier, optionally prefixing it with the module name
+     * Write a child JSON node identifier, optionally prefixing it with the module name
      * corresponding to its namespace.
      *
      * @param schema Schema context
@@ -58,7 +55,7 @@ abstract class JSONStreamWriterContext {
      * @param qname Namespace/name tuple
      * @throws IOException when the writer reports it
      */
-    protected final void writeJsonIdentifier(final SchemaContext schema, final Writer writer, final QName qname) throws IOException {
+    final void writeChildJsonIdentifier(final SchemaContext schema, final Writer writer, final QName qname) throws IOException {
         writer.append('"');
 
         // Prepend module name if namespaces do not match
@@ -75,6 +72,19 @@ abstract class JSONStreamWriterContext {
         writer.append("\":");
     }
 
+    /**
+     * Write our JSON node identifier, optionally prefixing it with the module name
+     * corresponding to its namespace.
+     *
+     * @param schema Schema context
+     * @param writer Output writer
+     * @param qname Namespace/name tuple
+     * @throws IOException when the writer reports it
+     */
+    protected final void writeMyJsonIdentifier(final SchemaContext schema, final Writer writer, final QName qname) throws IOException {
+        parent.writeChildJsonIdentifier(schema, writer, qname);
+    }
+
     /**
      * Return the namespace associated with current node.
      *
@@ -158,4 +168,5 @@ abstract class JSONStreamWriterContext {
         }
         return parent;
     }
+
 }
index ed7bd092c952c3e00552a6ab2aa5b7875f4673a9..9c0be476b1bb332e4d91a2a36f85a6e47cced61a 100644 (file)
@@ -24,7 +24,7 @@ final class JSONStreamWriterListContext extends JSONStreamWriterQNameContext {
 
     @Override
     protected void emitStart(final SchemaContext schema, final Writer writer) throws IOException {
-        writeJsonIdentifier(schema, writer, getQName());
+        writeMyJsonIdentifier(schema, writer, getQName());
         writer.append('[');
     }
 
index f5e5d487779404a6749e5bc57613390a116f5bcc..91c6ca70ae2c5a613984610bbdba44ae5aeca598 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.data.codec.gson;
 
 import java.io.IOException;
 import java.io.Writer;
-
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -25,7 +24,7 @@ final class JSONStreamWriterNamedObjectContext extends JSONStreamWriterObjectCon
 
     @Override
     protected void emitStart(final SchemaContext schema, final Writer writer) throws IOException {
-        writeJsonIdentifier(schema, writer, getQName());
+        writeMyJsonIdentifier(schema, writer, getQName());
         super.emitStart(schema, writer);
     }
-}
\ No newline at end of file
+}