Bug 7906: Fixed json parsing on patch request 88/52888/8
authorDavid Goldberg <gdavid@hpe.com>
Sun, 5 Mar 2017 12:50:33 +0000 (14:50 +0200)
committerJakub Morvay <jmorvay@cisco.com>
Tue, 14 Mar 2017 11:06:04 +0000 (11:06 +0000)
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 <gdavid@hpe.com>
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPATCHBodyReader.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPATCHBodyReader.java
restconf/sal-rest-connector/src/test/resources/instanceidentifier/json/jsonPATCHdata.json
restconf/sal-rest-connector/src/test/resources/instanceidentifier/yang/instance-identifier-patch-module.yang

index 014818c2d9f63ed343353a88a644c14d91a75cd1..9968a25fc06adcdf0feae4a1b7dacc3b3eb0d771 100644 (file)
@@ -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(",");
                         }
index 0e5f5c74ec0e92b923950542539c920dbcb1cb8f..e139e65d91e11c9ca282e3d03b9db03424b1f669 100644 (file)
@@ -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;
index e254502ff8e73831bc56f5e2cc811221f794a5ca..e027a7667283685ff9f4d020c38da0ccbb326179 100644 (file)
           "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
+}
index 11b4684da1ef68bcfb7ae0e8c73a8526d36e9f9f..02c1c2eaaaa3f282b39437ba652f904c1ecfeb25 100644 (file)
@@ -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
+}