From cc3f63f7d403f66a9761e27ae6afcfd30ec48df0 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 26 Dec 2017 11:57:08 +0100 Subject: [PATCH] YANGTOOLS-766: introduce JSONCodecFactorySupplier We need two separate instances of JSONCodecFactory factory methods, each with its own conformance, so that we can properly spin out codecs compliant to RFC7951 and draft-lhotka-netmod-yang-json-02. This patch provides a new API entrypoints for specifying these, without actually providing distinct codecs. It also provides proper JsonParserStream factory methods which take JSONCodecFactory instead of plain SchemaContext (and thus assuming JSONCodecFactory implementation). Change-Id: Ib2b402ed865903432645632e89c9b0e04851a05c Signed-off-by: Robert Varga --- .../data/codec/gson/JSONCodecFactory.java | 94 +++------ .../codec/gson/JSONCodecFactorySupplier.java | 199 ++++++++++++++++++ .../data/codec/gson/JsonParserStream.java | 84 ++++++-- .../data/codec/gson/AnyXmlSupportTest.java | 6 +- .../yang/data/codec/gson/Bug4501Test.java | 6 +- .../yang/data/codec/gson/Bug4969Test.java | 6 +- .../yang/data/codec/gson/Bug5446Test.java | 4 +- .../yang/data/codec/gson/Bug6112Test.java | 3 +- .../yang/data/codec/gson/Bug7246Test.java | 4 +- .../yang/data/codec/gson/Bug8083Test.java | 12 +- .../gson/JsonStreamToNormalizedNodeTest.java | 12 +- .../gson/NormalizedNodeToJsonStreamTest.java | 2 +- .../gson/StreamToNormalizedNodeTest.java | 10 +- .../yang/data/codec/gson/TestUtils.java | 2 +- .../gson/YangModeledAnyXmlSupportTest.java | 7 +- .../data/util/codec/AbstractCodecFactory.java | 2 + 16 files changed, 340 insertions(+), 113 deletions(-) create mode 100644 yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactorySupplier.java diff --git a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactory.java b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactory.java index 0a5e082276..5cfe1784f1 100644 --- a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactory.java +++ b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactory.java @@ -7,13 +7,12 @@ */ package org.opendaylight.yangtools.yang.data.codec.gson; +import static com.google.common.base.Verify.verifyNotNull; + import com.google.common.annotations.Beta; -import com.google.common.base.Stopwatch; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import java.util.List; import java.util.Optional; +import java.util.function.BiFunction; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.data.impl.codec.AbstractIntegerStringCodec; import org.opendaylight.yangtools.yang.data.impl.codec.BinaryStringCodec; @@ -24,14 +23,7 @@ import org.opendaylight.yangtools.yang.data.impl.codec.EnumStringCodec; import org.opendaylight.yangtools.yang.data.impl.codec.StringStringCodec; import org.opendaylight.yangtools.yang.data.util.codec.AbstractCodecFactory; import org.opendaylight.yangtools.yang.data.util.codec.CodecCache; -import org.opendaylight.yangtools.yang.data.util.codec.LazyCodecCache; -import org.opendaylight.yangtools.yang.data.util.codec.NoopCodecCache; -import org.opendaylight.yangtools.yang.data.util.codec.PrecomputedCodecCache; -import org.opendaylight.yangtools.yang.data.util.codec.SharedCodecCache; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition; @@ -51,8 +43,6 @@ import org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Factory for creating JSON equivalents of codecs. Each instance of this object is bound to @@ -65,56 +55,12 @@ import org.slf4j.LoggerFactory; */ @Beta public final class JSONCodecFactory extends AbstractCodecFactory> { - private static final class EagerCacheLoader extends CacheLoader { - @Override - public JSONCodecFactory load(final SchemaContext key) { - final Stopwatch sw = Stopwatch.createStarted(); - final LazyCodecCache> lazyCache = new LazyCodecCache<>(); - final JSONCodecFactory lazy = new JSONCodecFactory(key, lazyCache); - final int visitedLeaves = requestCodecsForChildren(lazy, key); - sw.stop(); - - final PrecomputedCodecCache> cache = lazyCache.toPrecomputed(); - LOG.debug("{} leaf nodes resulted in {} simple and {} complex codecs in {}", visitedLeaves, - cache.simpleSize(), cache.complexSize(), sw); - return new JSONCodecFactory(key, cache); - } - - private static int requestCodecsForChildren(final JSONCodecFactory lazy, final DataNodeContainer parent) { - int ret = 0; - for (DataSchemaNode child : parent.getChildNodes()) { - if (child instanceof TypedDataSchemaNode) { - lazy.codecFor((TypedDataSchemaNode) child); - ++ret; - } else if (child instanceof DataNodeContainer) { - ret += requestCodecsForChildren(lazy, (DataNodeContainer) child); - } - } - - return ret; - } - } - - private static final Logger LOG = LoggerFactory.getLogger(JSONCodecFactory.class); - - // Weak keys to retire the entry when SchemaContext goes away - private static final LoadingCache PRECOMPUTED = CacheBuilder.newBuilder() - .weakKeys().build(new EagerCacheLoader()); - - // Weak keys to retire the entry when SchemaContext goes away and to force identity-based lookup - private static final LoadingCache SHARED = CacheBuilder.newBuilder() - .weakKeys().build(new CacheLoader() { - @Override - public JSONCodecFactory load(final SchemaContext key) { - return new JSONCodecFactory(key, new SharedCodecCache<>()); - } - }); - private final JSONCodec iidCodec; - JSONCodecFactory(final SchemaContext context, final CodecCache> cache) { + JSONCodecFactory(final SchemaContext context, final CodecCache> cache, + final BiFunction iidCodecSupplier) { super(context, cache); - iidCodec = new JSONStringInstanceIdentifierCodec(context, this); + iidCodec = verifyNotNull(iidCodecSupplier.apply(context, this)); } /** @@ -137,9 +83,12 @@ public final class JSONCodecFactory extends AbstractCodecFactory> { * @param context SchemaContext instance * @return A sharable {@link JSONCodecFactory} * @throws NullPointerException if context is null + * + * @deprecated Use {@link JSONCodecFactorySupplier#getPrecomputed(SchemaContext)} instead. */ + @Deprecated public static JSONCodecFactory getPrecomputed(final SchemaContext context) { - return PRECOMPUTED.getUnchecked(context); + return JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getPrecomputed(context); } /** @@ -152,9 +101,12 @@ public final class JSONCodecFactory extends AbstractCodecFactory> { * @param context SchemaContext instance * @return A sharable {@link JSONCodecFactory}, or absent if such an implementation is not available. * @throws NullPointerException if context is null + * + * @deprecated Use {@link JSONCodecFactorySupplier#getPrecomputedIfAvailable(SchemaContext)} instead. */ + @Deprecated public static Optional getPrecomputedIfAvailable(final SchemaContext context) { - return Optional.ofNullable(PRECOMPUTED.getIfPresent(context)); + return JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getPrecomputedIfAvailable(context); } /** @@ -169,9 +121,12 @@ public final class JSONCodecFactory extends AbstractCodecFactory> { * @param context SchemaContext instance * @return A sharable {@link JSONCodecFactory} * @throws NullPointerException if context is null + * + * @deprecated Use {@link JSONCodecFactorySupplier#getShared(SchemaContext)} instead. */ + @Deprecated public static JSONCodecFactory getShared(final SchemaContext context) { - return SHARED.getUnchecked(context); + return JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(context); } /** @@ -186,9 +141,12 @@ public final class JSONCodecFactory extends AbstractCodecFactory> { * @param context SchemaContext instance * @return A non-sharable {@link JSONCodecFactory} * @throws NullPointerException if context is null + * + * @deprecated Use {@link JSONCodecFactorySupplier#createLazy(SchemaContext)} instead. */ + @Deprecated public static JSONCodecFactory createLazy(final SchemaContext context) { - return new JSONCodecFactory(context, new LazyCodecCache<>()); + return JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createLazy(context); } /** @@ -203,9 +161,12 @@ public final class JSONCodecFactory extends AbstractCodecFactory> { * @param context SchemaContext instance * @return A non-sharable {@link JSONCodecFactory} * @throws NullPointerException if context is null. + * + * @deprecated Use {@link JSONCodecFactorySupplier#createSimple(SchemaContext)} instead. */ + @Deprecated public static JSONCodecFactory createSimple(final SchemaContext context) { - return new JSONCodecFactory(context, NoopCodecCache.getInstance()); + return JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createSimple(context); } @Override @@ -245,8 +206,6 @@ public final class JSONCodecFactory extends AbstractCodecFactory> { @Override protected JSONCodec instanceIdentifierCodec(final InstanceIdentifierTypeDefinition type) { - // FIXME: there really are two favors, as 'require-instance true' needs to be validated. In order to deal - // with that, though, we need access to the current data store. return iidCodec; } @@ -304,5 +263,4 @@ public final class JSONCodecFactory extends AbstractCodecFactory> { protected JSONCodec unknownCodec(final UnknownTypeDefinition type) { return NullJSONCodec.INSTANCE; } - } diff --git a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactorySupplier.java b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactorySupplier.java new file mode 100644 index 0000000000..d3a04ed72f --- /dev/null +++ b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONCodecFactorySupplier.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.yangtools.yang.data.codec.gson; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +import com.google.common.annotations.Beta; +import com.google.common.base.Stopwatch; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import java.util.Optional; +import java.util.function.BiFunction; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yangtools.yang.data.util.codec.LazyCodecCache; +import org.opendaylight.yangtools.yang.data.util.codec.NoopCodecCache; +import org.opendaylight.yangtools.yang.data.util.codec.PrecomputedCodecCache; +import org.opendaylight.yangtools.yang.data.util.codec.SharedCodecCache; +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * API entry point for acquiring {@link JSONCodecFactory} instances. + * + * @author Robert Varga + */ +@Beta +public enum JSONCodecFactorySupplier { + /** + * Source of {@link JSONCodecFactory} instances compliant with RFC7951. + */ + // FIXME: YANGTOOLS-766: use a different codec + RFC7951(JSONStringInstanceIdentifierCodec::new), + /** + * Source of {@link JSONCodecFactory} instances compliant with RFC7951. + */ + DRAFT_LHOTKA_NETMOD_YANG_JSON_02(JSONStringInstanceIdentifierCodec::new); + + private static final Logger LOG = LoggerFactory.getLogger(JSONCodecFactorySupplier.class); + + private static final class EagerCacheLoader extends CacheLoader { + private final BiFunction + iidCodecSupplier; + + EagerCacheLoader(final BiFunction + iidCodecSupplier) { + this.iidCodecSupplier = requireNonNull(iidCodecSupplier); + } + + @Override + public JSONCodecFactory load(final SchemaContext key) { + final Stopwatch sw = Stopwatch.createStarted(); + final LazyCodecCache> lazyCache = new LazyCodecCache<>(); + final JSONCodecFactory lazy = new JSONCodecFactory(key, lazyCache, iidCodecSupplier); + final int visitedLeaves = requestCodecsForChildren(lazy, key); + sw.stop(); + + final PrecomputedCodecCache> cache = lazyCache.toPrecomputed(); + LOG.debug("{} leaf nodes resulted in {} simple and {} complex codecs in {}", visitedLeaves, + cache.simpleSize(), cache.complexSize(), sw); + return new JSONCodecFactory(key, cache, iidCodecSupplier); + } + + private static int requestCodecsForChildren(final JSONCodecFactory lazy, final DataNodeContainer parent) { + int ret = 0; + for (DataSchemaNode child : parent.getChildNodes()) { + if (child instanceof TypedDataSchemaNode) { + lazy.codecFor((TypedDataSchemaNode) child); + ++ret; + } else if (child instanceof DataNodeContainer) { + ret += requestCodecsForChildren(lazy, (DataNodeContainer) child); + } + } + + return ret; + } + } + + private final BiFunction iidCodecSupplier; + + // Weak keys to retire the entry when SchemaContext goes away + private final LoadingCache precomputed; + + // Weak keys to retire the entry when SchemaContext goes away and to force identity-based lookup + private final LoadingCache shared; + + JSONCodecFactorySupplier( + final BiFunction iidCodecSupplier) { + this.iidCodecSupplier = requireNonNull(iidCodecSupplier); + precomputed = CacheBuilder.newBuilder().weakKeys().build(new EagerCacheLoader(iidCodecSupplier)); + shared = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader() { + @Override + public JSONCodecFactory load(final SchemaContext key) { + return new JSONCodecFactory(key, new SharedCodecCache<>(), iidCodecSupplier); + } + }); + } + + /** + * Get a thread-safe, eagerly-caching {@link JSONCodecFactory} for a SchemaContext. This method can, and will, + * return the same instance as long as the associated SchemaContext is present. Returned object can be safely + * used by multiple threads concurrently. If the SchemaContext instance does not have a cached instance + * of {@link JSONCodecFactory}, it will be completely precomputed before this method will return. + * + *

+ * Choosing this implementation is appropriate when the memory overhead of keeping a full codec tree is not as + * great a concern as predictable performance. When compared to the implementation returned by + * {@link #getShared(SchemaContext)}, this implementation is expected to offer higher performance and have lower + * peak memory footprint when most of the SchemaContext is actually in use. + * + *

+ * For call sites which do not want to pay the CPU cost of pre-computing this implementation, but still would like + * to use it if is available (by being populated by some other caller), you can use + * {@link #getPrecomputedIfAvailable(SchemaContext)}. + * + * @param context SchemaContext instance + * @return A sharable {@link JSONCodecFactory} + * @throws NullPointerException if context is null + */ + public @NonNull JSONCodecFactory getPrecomputed(final @NonNull SchemaContext context) { + return verifyNotNull(precomputed.getUnchecked(context)); + } + + /** + * Get a thread-safe, eagerly-caching {@link JSONCodecFactory} for a SchemaContext, if it is available. This + * method is a non-blocking equivalent of {@link #getPrecomputed(SchemaContext)} for use in code paths where + * the potential of having to pre-compute the implementation is not acceptable. One such scenario is when the + * code base wants to opportunistically take advantage of pre-computed version, but is okay with a fallback to + * a different implementation. + * + * @param context SchemaContext instance + * @return A sharable {@link JSONCodecFactory}, or absent if such an implementation is not available. + * @throws NullPointerException if context is null + */ + public @NonNull Optional getPrecomputedIfAvailable(final @NonNull SchemaContext context) { + return Optional.ofNullable(precomputed.getIfPresent(context)); + } + + /** + * Get a thread-safe, lazily-caching {@link JSONCodecFactory} for a SchemaContext. This method can, and will, + * return the same instance as long as the associated SchemaContext is present or the factory is not invalidated + * by memory pressure. Returned object can be safely used by multiple threads concurrently. + * + *

+ * Choosing this implementation is a safe default, as it will not incur prohibitive blocking, nor will it tie up + * memory in face of pressure. + * + * @param context SchemaContext instance + * @return A sharable {@link JSONCodecFactory} + * @throws NullPointerException if context is null + */ + public @NonNull JSONCodecFactory getShared(final @NonNull SchemaContext context) { + return verifyNotNull(shared.getUnchecked(context)); + } + + /** + * Create a new thread-unsafe, lazily-caching {@link JSONCodecFactory} for a SchemaContext. This method will + * return distinct objects every time it is invoked. Returned object may not be used from multiple threads + * concurrently. + * + *

+ * This implementation is appropriate for one-off serialization from a single thread. It will aggressively cache + * codecs for reuse and will tie them up in memory until the factory is freed. + * + * @param context SchemaContext instance + * @return A non-sharable {@link JSONCodecFactory} + * @throws NullPointerException if context is null + */ + public @NonNull JSONCodecFactory createLazy(final @NonNull SchemaContext context) { + return new JSONCodecFactory(context, new LazyCodecCache<>(), iidCodecSupplier); + } + + /** + * Create a simplistic, thread-safe {@link JSONCodecFactory} for a {@link SchemaContext}. This method will return + * distinct objects every time it is invoked. Returned object may be use from multiple threads concurrently. + * + *

+ * This implementation exists mostly for completeness only, as it does not perform any caching at all and each codec + * is computed every time it is requested. This may be useful in extremely constrained environments, where memory + * footprint is more critical than performance. + * + * @param context SchemaContext instance + * @return A non-sharable {@link JSONCodecFactory} + * @throws NullPointerException if context is null. + */ + public @NonNull JSONCodecFactory createSimple(final @NonNull SchemaContext context) { + return new JSONCodecFactory(context, NoopCodecCache.getInstance(), iidCodecSupplier); + } +} diff --git a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java index bb35ce8198..93c0165443 100644 --- a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java +++ b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; import javax.xml.transform.dom.DOMSource; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.odlext.model.api.YangModeledAnyXmlSchemaNode; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; @@ -69,33 +70,84 @@ public final class JsonParserStream implements Closeable, Flushable { private final Deque namespaces = new ArrayDeque<>(); private final NormalizedNodeStreamWriter writer; private final JSONCodecFactory codecs; - private final SchemaContext schema; private final DataSchemaNode parentNode; - private JsonParserStream(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext, - final JSONCodecFactory codecs, final DataSchemaNode parentNode) { - this.schema = requireNonNull(schemaContext); + private JsonParserStream(final NormalizedNodeStreamWriter writer, final JSONCodecFactory codecs, + final DataSchemaNode parentNode) { this.writer = requireNonNull(writer); this.codecs = requireNonNull(codecs); this.parentNode = parentNode; } - private JsonParserStream(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext, - final DataSchemaNode parentNode) { - this(writer, schemaContext, JSONCodecFactory.getShared(schemaContext), parentNode); + /** + * Create a new {@link JsonParserStream} backed by specified {@link NormalizedNodeStreamWriter} + * and {@link JSONCodecFactory}. The stream will be logically rooted at the top of the SchemaContext associated + * with the specified codec factory. + * + * @param writer NormalizedNodeStreamWriter to use for instantiation of normalized nodes + * @param codecFactory {@link JSONCodecFactory} to use for parsing leaves + * @return A new {@link JsonParserStream} + * @throws NullPointerException if any of the arguments are null + */ + public static JsonParserStream create(final @NonNull NormalizedNodeStreamWriter writer, + final @NonNull JSONCodecFactory codecFactory) { + return new JsonParserStream(writer, codecFactory, codecFactory.getSchemaContext()); } - public static JsonParserStream create(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext, - final SchemaNode parentNode) { + /** + * Create a new {@link JsonParserStream} backed by specified {@link NormalizedNodeStreamWriter} + * and {@link JSONCodecFactory}. The stream will be logically rooted at the specified parent node. + * + * @param writer NormalizedNodeStreamWriter to use for instantiation of normalized nodes + * @param codecFactory {@link JSONCodecFactory} to use for parsing leaves + * @param parentNode Logical root node + * @return A new {@link JsonParserStream} + * @throws NullPointerException if any of the arguments are null + */ + public static JsonParserStream create(final @NonNull NormalizedNodeStreamWriter writer, + final @NonNull JSONCodecFactory codecFactory, final @NonNull SchemaNode parentNode) { if (parentNode instanceof RpcDefinition) { - return new JsonParserStream(writer, schemaContext, new RpcAsContainer((RpcDefinition) parentNode)); + return new JsonParserStream(writer, codecFactory, new RpcAsContainer((RpcDefinition) parentNode)); } - checkArgument(parentNode instanceof DataSchemaNode, "Instance of DataSchemaNode class awaited."); - return new JsonParserStream(writer, schemaContext, (DataSchemaNode) parentNode); + checkArgument(parentNode instanceof DataSchemaNode, "An instance of DataSchemaNode is expected, %s supplied", + parentNode); + return new JsonParserStream(writer, codecFactory, (DataSchemaNode) parentNode); + } + + /** + * Create a new {@link JsonParserStream} backed by specified {@link NormalizedNodeStreamWriter} + * and {@link SchemaContext}. The stream will be logically rooted at the top of the supplied SchemaContext. + * + * @param writer NormalizedNodeStreamWriter to use for instantiation of normalized nodes + * @param schemaContext {@link SchemaContext} to use + * @return A new {@link JsonParserStream} + * @throws NullPointerException if any of the arguments are null + * + * @deprecated Use {@link #create(NormalizedNodeStreamWriter, JSONCodecFactory)} instead. + */ + @Deprecated + public static JsonParserStream create(final @NonNull NormalizedNodeStreamWriter writer, + final @NonNull SchemaContext schemaContext) { + return create(writer, JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); } - public static JsonParserStream create(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext) { - return new JsonParserStream(writer, schemaContext, schemaContext); + /** + * Create a new {@link JsonParserStream} backed by specified {@link NormalizedNodeStreamWriter} + * and {@link SchemaContext}. The stream will be logically rooted at the specified parent node. + * + * @param writer NormalizedNodeStreamWriter to use for instantiation of normalized nodes + * @param schemaContext {@link SchemaContext} to use + * @param parentNode Logical root node + * @return A new {@link JsonParserStream} + * @throws NullPointerException if any of the arguments are null + * + * @deprecated Use {@link #create(NormalizedNodeStreamWriter, JSONCodecFactory, SchemaNode)} instead. + */ + @Deprecated + public static JsonParserStream create(final @NonNull NormalizedNodeStreamWriter writer, + final @NonNull SchemaContext schemaContext, final @NonNull SchemaNode parentNode) { + return create(writer, JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), + parentNode); } public JsonParserStream parse(final JsonReader reader) { @@ -305,7 +357,7 @@ public final class JsonParserStream implements Closeable, Flushable { moduleNamePart = childName.substring(0, lastIndexOfColon); nodeNamePart = childName.substring(lastIndexOfColon + 1); - final Iterator m = schema.findModules(moduleNamePart).iterator(); + final Iterator m = codecs.getSchemaContext().findModules(moduleNamePart).iterator(); namespace = m.hasNext() ? m.next().getNamespace() : null; } else { nodeNamePart = childName; @@ -335,7 +387,7 @@ public final class JsonParserStream implements Closeable, Flushable { for (final URI potentialUri : potentialUris) { builder.append('\n'); //FIXME how to get information about revision from JSON input? currently first available is used. - builder.append(schema.findModules(potentialUri).iterator().next().getName()); + builder.append(codecs.getSchemaContext().findModules(potentialUri).iterator().next().getName()); } return builder.toString(); } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java index bac5a4144c..19a47fe794 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java @@ -67,7 +67,8 @@ public class AnyXmlSupportTest { // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); @@ -102,7 +103,8 @@ public class AnyXmlSupportTest { final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java index cb05b63a1d..eee52da712 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java @@ -46,7 +46,8 @@ public class Bug4501Test { final String inputJson = loadTextFile("/bug-4501/json/foo-correct.json"); final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertTrue(transformedInput instanceof UnkeyedListNode); @@ -64,7 +65,8 @@ public class Bug4501Test { final String inputJson = loadTextFile("/bug-4501/json/foo-incorrect.json"); final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); try { jsonParser.parse(new JsonReader(new StringReader(inputJson))); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java index 5330bd0d33..c1f30b46c6 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java @@ -44,7 +44,8 @@ public class Bug4969Test { final String inputJson = TestUtils.loadTextFile("/bug-4969/json/foo.json"); final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, context); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(context)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); @@ -102,7 +103,8 @@ public class Bug4969Test { final String inputJson = TestUtils.loadTextFile("/leafref/json/data.json"); final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, context); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(context)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java index 7eb6054e68..4d0600a258 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java @@ -75,8 +75,8 @@ public class Bug5446Test { final NormalizedNode inputStructure) throws IOException { final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter( - JSONCodecFactory.getShared(schemaContext), SchemaPath.ROOT, null, - JsonWriterFactory.createJsonWriter(writer, 2)); + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), SchemaPath.ROOT, null, + JsonWriterFactory.createJsonWriter(writer, 2)); final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); nodeWriter.write(inputStructure); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java index c257a3af0a..eaffe4c15a 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java @@ -43,7 +43,8 @@ public class Bug6112Test { final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); return result.getResult(); } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java index d2d1bbbdcb..86a0057551 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java @@ -62,8 +62,8 @@ public class Bug7246Test { throws IOException { final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter( - JSONCodecFactory.getShared(schemaContext), path, URI.create(NS), - JsonWriterFactory.createJsonWriter(writer, 2)); + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), path, + URI.create(NS), JsonWriterFactory.createJsonWriter(writer, 2)); final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); nodeWriter.write(inputStructure); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java index fb3e195c9a..138841739f 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java @@ -35,7 +35,8 @@ public class Bug8083Test { // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.RFC7951.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); @@ -49,7 +50,8 @@ public class Bug8083Test { // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); @@ -63,7 +65,8 @@ public class Bug8083Test { // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); @@ -77,7 +80,8 @@ public class Bug8083Test { // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java index c0599b7b6b..822bda7f6f 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java @@ -195,7 +195,8 @@ public class JsonStreamToNormalizedNodeTest { final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, parentNode); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), parentNode); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); @@ -208,7 +209,8 @@ public class JsonStreamToNormalizedNodeTest { final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, parentNode); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), parentNode); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); @@ -247,7 +249,8 @@ public class JsonStreamToNormalizedNodeTest { .build()) .build()).build(); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertNotNull(transformedInput); @@ -258,7 +261,8 @@ public class JsonStreamToNormalizedNodeTest { final NormalizedNode awaitedStructure) { final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); assertEquals("Transformation of json input to normalized node wasn't successful.", awaitedStructure, diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java index 2f9fa49d1a..bf30b77bc3 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java @@ -312,7 +312,7 @@ public class NormalizedNodeToJsonStreamTest { final NormalizedNode inputStructure) throws IOException { final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter( - JSONCodecFactory.getShared(schemaContext), SchemaPath.ROOT, null, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), SchemaPath.ROOT, null, JsonWriterFactory.createJsonWriter(writer, 2)); final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); nodeWriter.write(inputStructure); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java index 0591c5e2c7..9a968cb43d 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java @@ -16,7 +16,6 @@ import java.io.StringReader; import java.io.StringWriter; import java.net.URISyntaxException; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; @@ -56,7 +55,8 @@ public class StreamToNormalizedNodeTest { final LoggingNormalizedNodeStreamWriter logWriter = new LoggingNormalizedNodeStreamWriter(); // JSON -> StreamWriter parser - try (JsonParserStream jsonHandler = JsonParserStream.create(logWriter, schemaContext)) { + try (JsonParserStream jsonHandler = JsonParserStream.create(logWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext))) { // Process multiple readers, flush()/close() as needed jsonHandler.parse(reader); } @@ -66,7 +66,6 @@ public class StreamToNormalizedNodeTest { * Demonstrates how to create an immutable NormalizedNode tree from a {@link JsonReader} and * then writes the data back into string representation. */ - @Ignore @Test public void immutableNormalizedNodeStreamWriterDemonstration() throws IOException { /* @@ -79,7 +78,8 @@ public class StreamToNormalizedNodeTest { final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); // JSON -> StreamWriter parser - try (JsonParserStream handler = JsonParserStream.create(streamWriter, schemaContext)) { + try (JsonParserStream handler = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext))) { handler.parse(new JsonReader(new StringReader(streamAsString))); } @@ -101,7 +101,7 @@ public class StreamToNormalizedNodeTest { // StreamWriter which outputs JSON strings // StreamWriter which outputs JSON strings final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter( - JSONCodecFactory.getShared(schemaContext), SchemaPath.ROOT, null, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), SchemaPath.ROOT, null, JsonWriterFactory.createJsonWriter(writer, 2)); // NormalizedNode -> StreamWriter diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java index a8c512301f..280fa592e7 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/TestUtils.java @@ -69,7 +69,7 @@ public final class TestUtils { final SchemaPath rootPath) throws IOException { final Writer writer = new StringWriter(); final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter( - JSONCodecFactory.getShared(schemaContext), rootPath, null, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), rootPath, null, JsonWriterFactory.createJsonWriter(writer, 2)); final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); nodeWriter.write(data); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java index de041d6b37..4da8a82bac 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java @@ -83,7 +83,8 @@ public class YangModeledAnyXmlSupportTest { final String inputJson = loadTextFile("/yang-modeled-anyxml/json/baz.json"); final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); - final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext); + final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext)); jsonParser.parse(new JsonReader(new StringReader(inputJson))); final NormalizedNode transformedInput = result.getResult(); @@ -109,8 +110,8 @@ public class YangModeledAnyXmlSupportTest { final NormalizedNode inputStructure) throws IOException { final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter( - JSONCodecFactory.getShared(schemaContext), SchemaPath.ROOT, null, - JsonWriterFactory.createJsonWriter(writer, 2)); + JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), SchemaPath.ROOT, null, + JsonWriterFactory.createJsonWriter(writer, 2)); final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); nodeWriter.write(inputStructure); diff --git a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/codec/AbstractCodecFactory.java b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/codec/AbstractCodecFactory.java index 6699581dcc..ab52a2ec9b 100644 --- a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/codec/AbstractCodecFactory.java +++ b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/codec/AbstractCodecFactory.java @@ -116,6 +116,8 @@ public abstract class AbstractCodecFactory> { protected abstract T identityRefCodec(IdentityrefTypeDefinition type, QNameModule module); + // FIXME: there really are two favors, as 'require-instance true' needs to be validated. In order to deal + // with that, though, we need access to the current data store. protected abstract T instanceIdentifierCodec(InstanceIdentifierTypeDefinition type); protected abstract T int8Codec(Int8TypeDefinition type); -- 2.36.6