@Test public void testSerializeRpc_in() throws Exception { Optional<RpcDefinition> loadedRpc = ConverterUtils.loadRpc(schemaContext, SIMPLE_IO_RPC_QNAME); Writer serializedRpc = bindingSerializer.serializeRpc(loadedRpc.get().getInput(), testedSimpleRpcInputNormalizedNodes); Assert.assertFalse(Strings.isNullOrEmpty(serializedRpc.toString())); LOG.info(serializedRpc.toString()); }
@Override public Writer serializeRpc(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode) throws SerializationException { Writer writer = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(writer); JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createLazy(this.schemaContext); String localName = schemaNode.getQName().getLocalName(); URI namespace = schemaNode.getQName().getNamespace(); NormalizedNodeStreamWriter create = JSONNormalizedNodeStreamWriter.createExclusiveWriter(jsonCodecFactory, schemaNode.getPath(), namespace, jsonWriter); try (NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(create)) { jsonWriter.beginObject().name(localName); for (NormalizedNode<?, ?> child : ((ContainerNode) normalizedNode).getValue()) { normalizedNodeWriter.write(child); } if (!writer.toString().endsWith("}")) { jsonWriter.endObject(); } } catch (IOException ioe) { throw new SerializationException(ioe); } return writer; }
JsonNodeConverter implements NodeConverter { @Override public Writer serializeRpc(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode) throws SerializationException { Writer writer = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(writer); JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createLazy(this.schemaContext); String localName = schemaNode.getQName().getLocalName(); URI namespace = schemaNode.getQName().getNamespace(); NormalizedNodeStreamWriter create = JSONNormalizedNodeStreamWriter.createExclusiveWriter(jsonCodecFactory, schemaNode.getPath(), namespace, jsonWriter); try (NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(create)) { jsonWriter.beginObject().name(localName); for (NormalizedNode<?, ?> child : ((ContainerNode) normalizedNode).getValue()) { normalizedNodeWriter.write(child); } if (!writer.toString().endsWith("}")) { jsonWriter.endObject(); } } catch (IOException ioe) { throw new SerializationException(ioe); } return writer; } }
JsonNodeConverter implements NodeConverter { @Override public Writer serializeRpc(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode) throws SerializationException { Writer writer = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(writer); JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createLazy(this.schemaContext); String localName = schemaNode.getQName().getLocalName(); URI namespace = schemaNode.getQName().getNamespace(); NormalizedNodeStreamWriter create = JSONNormalizedNodeStreamWriter.createExclusiveWriter(jsonCodecFactory, schemaNode.getPath(), namespace, jsonWriter); try (NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(create)) { jsonWriter.beginObject().name(localName); for (NormalizedNode<?, ?> child : ((ContainerNode) normalizedNode).getValue()) { normalizedNodeWriter.write(child); } if (!writer.toString().endsWith("}")) { jsonWriter.endObject(); } } catch (IOException ioe) { throw new SerializationException(ioe); } return writer; } JsonNodeConverter(final SchemaContext schemaContext); }
JsonNodeConverter implements NodeConverter { @Override public Writer serializeRpc(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode) throws SerializationException { Writer writer = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(writer); JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createLazy(this.schemaContext); String localName = schemaNode.getQName().getLocalName(); URI namespace = schemaNode.getQName().getNamespace(); NormalizedNodeStreamWriter create = JSONNormalizedNodeStreamWriter.createExclusiveWriter(jsonCodecFactory, schemaNode.getPath(), namespace, jsonWriter); try (NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(create)) { jsonWriter.beginObject().name(localName); for (NormalizedNode<?, ?> child : ((ContainerNode) normalizedNode).getValue()) { normalizedNodeWriter.write(child); } if (!writer.toString().endsWith("}")) { jsonWriter.endObject(); } } catch (IOException ioe) { throw new SerializationException(ioe); } return writer; } 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); }
JsonNodeConverter implements NodeConverter { @Override public Writer serializeRpc(final SchemaNode schemaNode, final NormalizedNode<?, ?> normalizedNode) throws SerializationException { Writer writer = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(writer); JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.createLazy(this.schemaContext); String localName = schemaNode.getQName().getLocalName(); URI namespace = schemaNode.getQName().getNamespace(); NormalizedNodeStreamWriter create = JSONNormalizedNodeStreamWriter.createExclusiveWriter(jsonCodecFactory, schemaNode.getPath(), namespace, jsonWriter); try (NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(create)) { jsonWriter.beginObject().name(localName); for (NormalizedNode<?, ?> child : ((ContainerNode) normalizedNode).getValue()) { normalizedNodeWriter.write(child); } if (!writer.toString().endsWith("}")) { jsonWriter.endObject(); } } catch (IOException ioe) { throw new SerializationException(ioe); } return writer; } 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);  }