JsonNodeConverter implements NodeConverter { @Override public NormalizedNode<?, ?> deserialize(final SchemaNode schemaNode, final Reader inputData) throws SerializationException { NormalizedNodeResult result = new NormalizedNodeResult(); JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createLazy(schemaContext); try (JsonReader reader = new JsonReader(inputData); NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); JsonParserStream jsonParser = JsonParserStream.create(streamWriter, jsonCodecFactory, schemaNode)) { jsonParser.parse(reader); } catch (IOException e) { throw new SerializationException(e); } return result.getResult(); } JsonNodeConverter(final SchemaContext schemaContext); @Override Writer serializeData(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode); @Override Writer serializeRpc(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode); @Override NormalizedNode<?, ?> deserialize(final SchemaNode schemaNode, final Reader inputData);  }
@Test public void testDeserializeData() throws Exception { NormalizedNode<?, ?> deserializeData = bindingSerializer.deserialize(schemaContext, new StringReader(loadResourceAsString("toaster.json"))); Assert.assertNotNull(deserializeData); LOG.info(deserializeData.toString()); }
@Test public void testDeserialize_in() throws Exception { Optional<RpcDefinition> loadRpc = ConverterUtils.loadRpc(schemaContext, SIMPLE_IO_RPC_QNAME); String loadIoRpcIn = loadResourceAsString("input-output-rpc-in.json"); NormalizedNode<?, ?> deserializeRpc = bindingSerializer.deserialize(loadRpc.get(), new StringReader(loadIoRpcIn)); Assert.assertNotNull(deserializeRpc); LOG.info(deserializeRpc.toString()); }
@Test public void testDeserialize_out() throws Exception { Optional<RpcDefinition> loadRpc = ConverterUtils.loadRpc(schemaContext, SIMPLE_IO_RPC_QNAME); String loadIoRpcOut = loadResourceAsString("input-output-rpc-out.json"); NormalizedNode<?, ?> deserializeRpc = bindingSerializer.deserialize(loadRpc.get(), new StringReader(loadIoRpcOut)); Assert.assertNotNull(deserializeRpc); LOG.info(deserializeRpc.toString()); }
@Test public void testDeserialize_container() throws SerializationException { NormalizedNode<?, ?> deserializeContainer = bindingSerializer.deserialize(this.schemaContext, new StringReader(loadResourceAsString("top-level-container.json"))); Assert.assertNotNull(deserializeContainer); LOG.info(deserializeContainer.toString()); }
@Test public void testDeserialize_container_rpc() throws SerializationException { Optional<RpcDefinition> loadRpcContainer = ConverterUtils.loadRpc(schemaContext, CONTAINER_IO_RPC_QNAME); NormalizedNode<?, ?> deserializeData = bindingSerializer.deserialize(loadRpcContainer.get(), new StringReader(loadResourceAsString("container-io-rpc.json"))); Assert.assertNotNull(deserializeData); }