Hi Robert, 

In this case, the CONSUMER *is cognizant* of what Clazz (NetworkTopology.class 
in below case) to use to get the NN(NormalizedNode) converted into 
corresponding BA. 

DataObject obj = 
BindingNormalizedNodeCodecRegistry.fromNormalizedNode(YangInstanceIdentifier.of(BindingReflections.findQName(NetworkTopology.class)),
 normalizedNode);

So if there is going to be multiple JSONs representing different NNs (and hence 
different BA DTOs), it would not be possible to use this approach ?

Regards
Muthu


-----Original Message-----
From: Robert Varga [mailto:n...@hq.sk] 
Sent: Thursday, September 01, 2016 4:27 AM
To: Sela, Guy; Muthukumaran K; controller-dev@lists.opendaylight.org; 
mdsal-...@lists.opendaylight.org; yangtools-...@lists.opendaylight.org
Subject: Re: [mdsal-dev] Serialize/Deserialize DTOs to JSON

On 08/24/2016 01:21 PM, Sela, Guy wrote:
> The only way it is working for me now, is the following (Some of it is 
> pseudo-code):
> "
> PRODUCER CODE:
> I have a 
> org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
>  in my hands (Got it from a DCN).
> This is the code I need to run in order to do what I'm trying:
> TopologyBuilder topologyBuilder = new TopologyBuilder(); 
> topologyBuilder.setKey(new TopologyKey(new TopologyId(new 
> Uri("ovsdb:1")))); 
> topologyBuilder.setNode(Collections.singletonList(node));
> NetworkTopologyBuilder ntBuilder = new NetworkTopologyBuilder(); 
> ntBuilder.setTopology(Collections.singletonList(topologyBuilder.build(
> ))); InstanceIdentifier path = 
> InstanceIdentifier.create(NetworkTopology.class);
> String json = TTPUtils.jsonStringFromDataObject(path, 
> ntBuilder.build(), true); Serialize the json...
> 
> CONSUMER CODE:
> NormalizedNode normalizedNode = 
> TTPUtils.normalizedNodeFromJsonString(jsonInput);
> DataObject obj = BindingNormalizedNodeCodecRegistry. 
> fromNormalizedNode(YangInstanceIdentifier.of(BindingReflections.findQN
> ame(NetworkTopology.class)), normalizedNode); NetworkTopology nt = 
> (NetworkTopology)obj; Node node = 
> nt.getTopology().get(0).getNode().get(0);
> return node;
> "
> 
> Is this what you guys meant by working with NormalizedNodes or is there a 
> better way?

Yes, pretty much. Since you mentioned getting the data from DCN -- you could 
use DOMDataBroker's DOMDataTreeChangeService extension to get the data in 
NormalizedNode format, skipping one conversion (and talking to JSON codec 
directly).

Bye,
Robert

_______________________________________________
controller-dev mailing list
controller-dev@lists.opendaylight.org
https://lists.opendaylight.org/mailman/listinfo/controller-dev

Reply via email to