Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

DescriptionResponse for getDataNode root nodeResponse for getDataNode non root node body when writing (root) DataNode
OperationGETGETPOST/PUT
xPath//bookstore/categories[@code='01']/

Response

/Body

{
   "bookstore-name":"Chapters",
   "categories":[ ... ]
}


{
    "code": "01",
    "name": "SciFi",
     ...

}

{
   "bookstore":{
     "bookstore-name":"Chapters",
      "categories":[ ... ]
  }
}

NotesThe response includes the 'value' of the bookstore node ie. the leaves and children<= Same the body needs to include the whole container object.

...

For the JSON output of Get DataNode we need to alter the DataMapUtils class. The function toDataMap translates a datanode object to a JSON output. We only want this to occur on the top node and as such we can create a new method which is called before toDataMap:


public static Map<String, Object> toDataMaptoDataMapTopNode(final DataNode dataNode) {
final booleanString isTopLevelNodenodeName = dataNode.getXpath().lastIndexOf('/') == 0;
if (isTopLevelNode) {
String containerName = substring(dataNode.getXpath().substringlastIndexOf(1'/');
return ImmutableMap.<String, Object>builder().put(containerName,
+ 1)
ImmutableMap.<String, Object>builder()
.putAll(dataNode.getLeaves())
.putAll(listElementsAsMap(dataNode.getChildDataNodes()))
.putAll(containerElementsAsMap(dataNode.getChildDataNodes()))
.build()
).build().replaceAll("\\[.*?\\]", "");
} else {
return ImmutableMap.<String, Object>builder()
.putAll(dataNode.getLeaves()).put(nodeName,
.putAll(listElementsAsMaptoDataMap(dataNode.getChildDataNodes()))
.putAll(containerElementsAsMap(dataNode.getChildDataNodes()))
.build();
}
}

We only want the container name on the top level of the JSON output and as such have to distinguish between a top level node and non top level node. We create an outer map to wrap the inner map which creates the appropriate levels in the JSON output. 

This produces the following response in the Post Request output:

DescriptionResponse for getDataNode root node

...

Response for getDataNode non root node
OperationGETGET
xPath//bookstore/categories[@code='01']

Response

/Body

{
    "bookstore": {
        "bookstore-name": "Easons",
        "categories":

...

[...]

    }

}

{
    "categories": {
        "code": "01",

...

        "name": "SciFi"

...

,
        "books": [...] 

...

     }

}

NotesResponse includes the container bookstoreThe response includes the list categories

Tests would need to be updated to accept the new JSON output which is returned. Examples would need to be updated in openapi

...