I am probably missing something, or not explaining myself well.
I'll give a fresh example.
I am holding a
"org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node"
in my hands.
Node node = new NodeBuilder().setKey(new NodeKey(new NodeId("asdsd"))).build();
After converting it to NormalizedNode I get:
ImmutableMapEntryNode{nodeIdentifier=(urn:TBD:params:xml:ns:yang:network-topology?revision=2013-10-21)node[{(urn:TBD:params:xml:ns:yang:network-topology?revision=2013-10-21)node-id=asdsd}],
value=[ImmutableLeafNode{nodeIdentifier=(urn:TBD:params:xml:ns:yang:network-topology?revision=2013-10-21)node-id,
value=asdsd, attributes={}}], attributes={}}
When I try to convert this NormalizedNode to a JsonString using the algorithm
used in the Test class[1], I get the following exception
Exception in thread "main" java.lang.IllegalArgumentException: List item is not
appropriate
at
com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
at
org.opendaylight.yangtools.yang.data.impl.codec.SchemaTracker.startListItem(SchemaTracker.java:144)
at
org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter.startMapEntryNode(JSONNormalizedNodeStreamWriter.java:156)
at
org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter$OrderedNormalizedNodeWriter.writeMapEntryNode(NormalizedNodeWriter.java:269)
at
org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.wasProcessedAsCompositeNode(NormalizedNodeWriter.java:210)
at
org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter.write(NormalizedNodeWriter.java:102)
at
org.opendaylight.newfederation.transform.GuyDemoUtils.normalizedNodeToJsonStreamTransformation(GuyDemoUtils.java:190)
at
org.opendaylight.newfederation.tests.JsonParsing.main(JsonParsing.java:115)
[1] The algorithm (I'm replacing schemaContext with the correct schemaContext):
private static String normalizedNodeToJsonStreamTransformation(final Writer
writer,
final NormalizedNode<?, ?> inputStructure) throws IOException {
final NormalizedNodeStreamWriter jsonStream =
JSONNormalizedNodeStreamWriter.
createExclusiveWriter(JSONCodecFactory.create(schemaContext),
SchemaPath.ROOT, null,
JsonWriterFactory.createJsonWriter(writer, 2));
final NormalizedNodeWriter nodeWriter =
NormalizedNodeWriter.forStreamWriter(jsonStream);
nodeWriter.write(inputStructure);
nodeWriter.close();
return writer.toString();
}
-----Original Message-----
From: Muthukumaran K [mailto:[email protected]]
Sent: Tuesday, August 23, 2016 5:51 PM
To: Sela, Guy <[email protected]>; Robert Varga <[email protected]>;
[email protected]; [email protected]
Subject: RE: [mdsal-dev] Serialize/Deserialize DTOs to JSON
Since NormalizedNode is a pre-requisite for the deserialization into json, this
seems to demonstrate how to get an entry from keyed list
https://github.com/opendaylight/yangtools/blob/master/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java
particularly 'keyedListNodeInContainer()'
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Sela, Guy
Sent: Tuesday, August 23, 2016 7:52 PM
To: Robert Varga; [email protected];
[email protected]
Subject: Re: [controller-dev] [mdsal-dev] Serialize/Deserialize DTOs to JSON
Sorry, I meant to ask about an entry of a list, not a leaf node.
I mean, let's say I have this yang model:
"
container elan-instances {
description
"elan instances configuration parameters. Elan instances support
both the VLAN and VNI based elans.";
list elan-instance {
max-elements "unbounded";
min-elements "0";
key "elan-instance-name";
description
"Specifies the name of the elan instance. It is a string of 1
to 31
case-sensitive characters.";
leaf elan-instance-name {
...
"
Can I convert a specific elan-instance ? Or do I have to convert something
bigger?
-----Original Message-----
From: Sela, Guy
Sent: Tuesday, August 23, 2016 4:49 PM
To: 'Robert Varga' <[email protected]>; [email protected];
[email protected]
Subject: RE: [mdsal-dev] Serialize/Deserialize DTOs to JSON
>From what I'm seeing so far, I can't convert a leaf node into a JSON string.
>The only entities I can convert are container or list.
Is this correct?
I got this from:
private SchemaTracker(final SchemaContext context, final SchemaPath path) {
SchemaNode current = SchemaUtils.findParentSchemaOnPath(context, path);
Preconditions.checkArgument(current instanceof
DataNodeContainer,"Schema path must point to container or list or an rpc
input/output. Supplied path %s pointed to: %s",path,current);
root = (DataNodeContainer) current;
}
When trying to create JSONNormalizedNodeStreamWriter
-----Original Message-----
From: Robert Varga [mailto:[email protected]]
Sent: Sunday, July 24, 2016 4:52 PM
To: Sela, Guy <[email protected]>; [email protected];
[email protected]
Subject: Re: [mdsal-dev] Serialize/Deserialize DTOs to JSON
On 07/24/2016 01:36 PM, Sela, Guy wrote:
> Hi,
>
> Is there an API that I can call which gets a DataObject as input and
> returns a JSON representation of it?
Not directly, as DataObject and related generated code is an access facade.
Primary data representation is NormalizedNode, hence you need to transform the
DTOs to NormalizedNodes (see mdsal-binding-dom-codec) and then use
yang-data-codec-gson (or -xml) to get the representation you seek.
I think TTPUtils (in TTP) does exactly that.
Bye,
Robert
_______________________________________________
controller-dev mailing list
[email protected]
https://lists.opendaylight.org/mailman/listinfo/controller-dev
_______________________________________________
controller-dev mailing list
[email protected]
https://lists.opendaylight.org/mailman/listinfo/controller-dev