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>
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.gson.stream.JsonWriter;
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 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;
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;
final JSONCodec<Object> codec = codecs.codecFor(schema.getType());
context.emittingChild(codecs.getSchemaContext(), writer, indent);
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());
}
writeValue(codec.serialize(value), codec.needQuotes());
}
@Override
public void anyxmlNode(final NodeIdentifier name, final Object value) throws IOException {
@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);
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);
}
writeValue(String.valueOf(value), true);
}
package org.opendaylight.yangtools.yang.data.codec.gson;
import com.google.common.base.Preconditions;
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 java.io.IOException;
import java.io.Writer;
import java.net.URI;
import javax.annotation.Nonnull;
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;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
- * 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
* corresponding to its namespace.
*
* @param schema Schema context
* @param qname Namespace/name tuple
* @throws IOException when the writer reports it
*/
* @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
writer.append('"');
// Prepend module name if namespaces do not match
+ /**
+ * 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.
*
/**
* Return the namespace associated with current node.
*
@Override
protected void emitStart(final SchemaContext schema, final Writer writer) throws IOException {
@Override
protected void emitStart(final SchemaContext schema, final Writer writer) throws IOException {
- writeJsonIdentifier(schema, writer, getQName());
+ writeMyJsonIdentifier(schema, writer, getQName());
import java.io.IOException;
import java.io.Writer;
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;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@Override
protected void emitStart(final SchemaContext schema, final Writer writer) throws IOException {
@Override
protected void emitStart(final SchemaContext schema, final Writer writer) throws IOException {
- writeJsonIdentifier(schema, writer, getQName());
+ writeMyJsonIdentifier(schema, writer, getQName());
super.emitStart(schema, writer);
}
super.emitStart(schema, writer);
}
-}
\ No newline at end of file