[CONTROLLER-654] singleton lists are not rendered as lists by StructuredDataToJsonProvider Created: 29/Jul/14  Updated: 25/Jul/23  Due: 01/Aug/14  Resolved: 01/Aug/14

Status: Resolved
Project: controller
Component/s: restconf
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Colin Dixon Assignee: Jozef Gloncak
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Mac OS
Platform: PC


External issue ID: 1449

 Description   

If I have a model with a list of string, like the leaf-list on line 32 here:
https://git.opendaylight.org/gerrit/#/c/8975/4/ttp-model/model/src/main/yang/ttp.yang

And I use the builder to add a singleton list of strings like this:
NDMMetadata NDMmeta = new NDMMetadataBuilder()
.setDoc(Arrays
.asList("TTP supporting L2 VLANs (unicast, multicast, flooding) with optional VID translation."))
.setAuthority("org.opennetworking.fawg").build();

When I covert it to JSON, I get a single string, not a list containing a single stiring. That is I get this:
{
"NDM_metadata":

{ "authority": "org.opennetworking.fawg", "doc": "TTP supporting L2 VLANs (unicast, multicast, flooding) with optional VID translation." }

}

but, I'd expect this:
{
"NDM_metadata":

{ "authority": "org.opennetworking.fawg", "doc": ["TTP supporting L2 VLANs (unicast, multicast, flooding) with optional VID translation."] }

}

Is this a bug or expected behavior?

If you want to check it out, this patch set has an example:
https://git.opendaylight.org/gerrit/#/c/8975/4/



 Comments   
Comment by Jozef Gloncak [ 30/Jul/14 ]

can you please specify how you convert NDMmeta object to JSON?

Comment by Jozef Gloncak [ 30/Jul/14 ]

Please, ignore my question. I have found it.

Comment by Jozef Gloncak [ 30/Jul/14 ]

Incorrect output is caused by incorrect using of
StructuredDataToJsonProvider.INSTANCE.writeTo() method.

First parameter of writeTo method is of type StructuredData. It was created with parameters

  • CompositeNode data - compNode (NDM_metadata container) (OK)
  • DataSchemaNode schema - context (represents whole DataSchema and not only schema for NDM_metadata) (WRONG)

You have to specify schema for concrete node. You can find concrete schema node in schema context:

  • by tracing down schema context programatically (marked as first solution in gerrit)
  • via ControllerContext.toInstanceIdentifier() method (marked as second solution)

https://git.opendaylight.org/gerrit/#/c/9487/1/ttp-model/model/src/test/java/org/opendaylight/ttp/model/test/TTPYangModelTest.java

The behavior when an entry of leaf-list was outputted like leaf and not like list of leaves was default behavior for case when schema for node isn't presented.

Comment by Colin Dixon [ 01/Aug/14 ]

Thanks for the help. For those who care, I modified Jozef's code to make it generic and you can find it here:
https://git.opendaylight.org/gerrit/#/c/9518/

I think most of the functionality or at least the getSchemaNodeForDataObject should be moved into the SchemaContext implementation where we can maintain a map from Class (and/or QName) to DataSchemaNode.

Generated at Wed Feb 07 19:53:33 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.