[ONOS-7875]Json serializer issue for boolean data type
Change-Id: I9a5f112573b4bfc2ad658aeee829516f8f45270f
diff --git a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
index 0790687..61234b6 100644
--- a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
+++ b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
@@ -106,6 +106,7 @@
case INT32:
case UINT16:
case UINT32:
+ case BOOLEAN:
treeString.append(v);
break;
default:
diff --git a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonWalker.java b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonWalker.java
index 46a5b98..bff5fec 100644
--- a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonWalker.java
+++ b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonWalker.java
@@ -186,7 +186,8 @@
JsonNode element = elements.next();
JsonNodeType eleType = element.getNodeType();
- if (eleType == JsonNodeType.STRING || eleType == JsonNodeType.NUMBER) {
+ if (eleType == JsonNodeType.STRING || eleType == JsonNodeType.NUMBER ||
+ eleType == JsonNodeType.BOOLEAN) {
addLeafDataNode(fieldName, element.asText(),
MULTI_INSTANCE_LEAF_VALUE_NODE);
dataNodeBuilder = SerializerHelper.exitDataNode(dataNodeBuilder);
@@ -202,7 +203,8 @@
while (elements.hasNext()) {
JsonNode element = elements.next();
JsonNodeType eleType = element.getNodeType();
- if (eleType != JsonNodeType.STRING && eleType != JsonNodeType.NUMBER) {
+ if (eleType != JsonNodeType.STRING && eleType != JsonNodeType.NUMBER &&
+ eleType != JsonNodeType.BOOLEAN) {
return false;
}
}
diff --git a/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java b/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java
index 9feeba5..831534a 100644
--- a/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java
+++ b/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java
@@ -76,10 +76,10 @@
private static String outputIdTestJson1 = "{\"jsonlist:c2\":{\"leaflist1" +
"\":[\"a\",\"b\",\"c\"],\"leaf1\":1,\"leaf2\":2,\"leaf3\":3," +
"\"leaf4\":4,\"leaf5\":5,\"leaf6\":6,\"leaf7\":\"7\",\"leaf8\"" +
- ":\"8\",\"leaf9\":\"true\",\"leaf10\":\"-922337203685477580.8\"" +
+ ":\"8\",\"leaf9\":true,\"leaf10\":\"-922337203685477580.8\"" +
",\"ll1\":[1,10],\"ll2\":[2,20],\"ll3\":[3,30],\"ll4\":[4,40],\"" +
"ll5\":[5,50],\"ll6\":[6,60],\"ll7\":[\"7\",\"70\"],\"ll8\":[\"" +
- "8\",\"80\"],\"ll9\":[\"true\",\"false\"],\"ll10\":[" +
+ "8\",\"80\"],\"ll9\":[true,false],\"ll10\":[" +
"\"-922337203685477580.8\",\"-922337203685477480.8\"]}}";
@Rule
public ExpectedException thrown = ExpectedException.none();
diff --git a/serializers/json/src/test/resources/demo1.yang b/serializers/json/src/test/resources/demo1.yang
index 1dd1ea2..48cad6f 100644
--- a/serializers/json/src/test/resources/demo1.yang
+++ b/serializers/json/src/test/resources/demo1.yang
@@ -79,6 +79,11 @@
type string;
}
}
+ container cont8 {
+ leaf leaf9 {
+ type boolean;
+ }
+ }
}
}
diff --git a/serializers/json/src/test/resources/test.json b/serializers/json/src/test/resources/test.json
index 47f726f..a626129 100644
--- a/serializers/json/src/test/resources/test.json
+++ b/serializers/json/src/test/resources/test.json
@@ -44,6 +44,9 @@
"string82",
"string83"
]
+ },
+ "cont8" : {
+ "leaf9" : true
}
}
]
diff --git a/serializers/json/src/test/resources/testinput1.json b/serializers/json/src/test/resources/testinput1.json
index 74ac948..583a57b 100644
--- a/serializers/json/src/test/resources/testinput1.json
+++ b/serializers/json/src/test/resources/testinput1.json
@@ -13,7 +13,7 @@
"leaf6": 6,
"leaf7": "7",
"leaf8": "8",
- "leaf9": "true",
+ "leaf9": true,
"leaf10": "-922337203685477580.8",
"ll1": [
1,