[YANGTOOLS-1003] Anyxml list data are wrapped in "array-element" Created: 10/Jun/19 Updated: 24/Jun/20 |
|
| Status: | Confirmed |
| Project: | yangtools |
| Component/s: | codecs |
| Affects Version/s: | 2.0.12, 2.1.10, 3.0.2, 4.0.8 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Medium |
| Reporter: | Richard Kosegi | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
Given rpc definition:
rpc some-action {
input {
anyxml data;
}
}
And data passed into restconf:
{
"input" : {
"data" : [
{ "key" : "value" }
]
}
}
results in following json element received from gson codec: "data" : { "array-element" : { "key" : " value" } }
This breaks how jsonrpc digests anyxml data from restconf. I can't find reference to this behavior in RFC7951, so I think this is a bug. |
| Comments |
| Comment by Robert Varga [ 13/Jun/19 ] |
|
This has been the behaviour from day one. The reason for 'array-element' is that XML encoding loses list encapsulation so if you read JSON anyxml and write the thing out you'd lose the brackets in data. JSON codec uses this information to accurately emit the brackets. If you use JSON codec to send out the result, you will get a correct JSON – not perfect, but it works. Now to fix this without regressing, JSON codec needs to do something similar as DOMSourceAnydata is doing, but as a subclass of DOMSource containing an unencapsulated tree (passed to DOMSource constructor) and an encapulated tree (kept as an additional field). JSON egress needs to recognize this subclass and pick the escaped tree when writing out JSON. |
| Comment by Richard Kosegi [ 16/Jun/19 ] |
|
Thanks rovarga for info. Can you elaborate a bit on "If you use JSON codec to send out the result"? Problem is actually in both ways. 1, when user use restconf to invoke RPC with anyxml in input, following code is called https://github.com/opendaylight/jsonrpc/blob/master/impl/src/main/java/org/opendaylight/jsonrpc/impl/JsonConverter.java#L219 Before we send anything out, I can modify data and apply fix. 2, But when response is received from external entity, following code is called https://github.com/opendaylight/jsonrpc/blob/master/impl/src/main/java/org/opendaylight/jsonrpc/impl/JsonRPCtoRPCBridge.java#L303 to form NormalizedNode. There is no way I'm aware of I can do anything here, RPC output will be wrapped in array-element (if RPC output has anyxml node and data contains list)
|
| Comment by Robert Varga [ 08/Oct/19 ] |
|
The constant comes from https://github.com/opendaylight/yangtools/blob/master/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java#L66 and is supposed to be eliminated when the DOMSource is streamed out again, i.e. in the JSON -> DOMSource -> JSON case. Not sure that works. The reason is that if the anyxml element represents a list, it needs to be captured as such – and hence it needs a containment node, which is not part of DOMSource specification – i.e. it would not be present were the anyxml node parsed from XML. As noted, this will need JSON-level event buffering, where the DOMSource view of anyxml will be not contain this hack use proper format. See YANGTOOLS-994 for details. |