From: David Goldberg Date: Sun, 5 Mar 2017 12:50:33 +0000 (+0200) Subject: Bug 7906: Fixed json parsing on patch request X-Git-Tag: release/carbon~41 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=d548af6597c884273cec0b306b1a2bd77912df48;p=netconf.git Bug 7906: Fixed json parsing on patch request Currently lists with simple objects (string, int, etc.) are not supported in the patch request. This commit adds support for that. Change-Id: I4310a683aa42271b914c5dd8c3349bb2bac9e971 Signed-off-by: David Goldberg --- diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java index 014818c2d9..9968a25fc0 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java @@ -273,7 +273,11 @@ public class JsonToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider value.append("["); while (in.hasNext()) { - readValueObject(value, in); + if (in.peek() == JsonToken.STRING) { + value.append("\"" + in.nextString() + "\""); + } else { + readValueObject(value, in); + } if (in.peek() != JsonToken.END_ARRAY) { value.append(","); } @@ -311,7 +315,11 @@ public class JsonToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider value.append("["); while (in.hasNext()) { - readValueObject(value, in); + if (in.peek() == JsonToken.STRING) { + value.append("\"" + in.nextString() + "\""); + } else { + readValueObject(value, in); + } if (in.peek() != JsonToken.END_ARRAY) { value.append(","); } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java index 0e5f5c74ec..e139e65d91 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java @@ -268,7 +268,11 @@ public class JsonToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider value.append("["); while (in.hasNext()) { - readValueObject(value, in); + if (in.peek() == JsonToken.STRING) { + value.append("\"" + in.nextString() + "\""); + } else { + readValueObject(value, in); + } if (in.peek() != JsonToken.END_ARRAY) { value.append(","); } @@ -306,7 +310,11 @@ public class JsonToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider value.append("["); while (in.hasNext()) { - readValueObject(value, in); + if (in.peek() == JsonToken.STRING) { + value.append("\"" + in.nextString() + "\""); + } else { + readValueObject(value, in); + } if (in.peek() != JsonToken.END_ARRAY) { value.append(","); } @@ -349,7 +357,7 @@ public class JsonToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider */ private static PATCHEntity prepareEditOperation(@Nonnull final PatchEdit edit) { if (edit.getOperation() != null && edit.getTargetSchemaNode() != null - && checkDataPresence(edit.getOperation(), (edit.getData() != null))) { + && checkDataPresence(edit.getOperation(), edit.getData() != null)) { if (isPatchOperationWithValue(edit.getOperation())) { // for lists allow to manipulate with list items through their parent final YangInstanceIdentifier targetNode; diff --git a/restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHdata.json b/restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHdata.json index e254502ff8..e027a76672 100644 --- a/restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHdata.json +++ b/restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHdata.json @@ -25,10 +25,11 @@ "my-list2": { "name": "my-leaf20", "my-leaf21": "I am leaf21-1", - "my-leaf22": "I am leaf22-1" + "my-leaf22": "I am leaf22-1", + "my-leaf-list": ["listelement"] } } } ] } -} \ No newline at end of file +} diff --git a/restconf/sal-rest-connector/src/test/resources/instanceidentifier/yang/instance-identifier-patch-module.yang b/restconf/sal-rest-connector/src/test/resources/instanceidentifier/yang/instance-identifier-patch-module.yang index 11b4684da1..02c1c2eaaa 100644 --- a/restconf/sal-rest-connector/src/test/resources/instanceidentifier/yang/instance-identifier-patch-module.yang +++ b/restconf/sal-rest-connector/src/test/resources/instanceidentifier/yang/instance-identifier-patch-module.yang @@ -38,7 +38,10 @@ module instance-identifier-patch-module { leaf my-leaf22 { type string; } + leaf-list my-leaf-list { + type string; + } } } } -} \ No newline at end of file +}