Handling empty text nodes 64/67864/1
authorAtul Gosain <agosain@luminanetworks.com>
Wed, 29 Nov 2017 02:07:08 +0000 (18:07 -0800)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 2 Feb 2018 13:54:36 +0000 (14:54 +0100)
This is a fix for an issue seen in the patch 63984 on yangtools.
It handles text nodes which are empty.

Change-Id: I6cf1096c511758154df6121d26bf36184385403f
Signed-off-by: Atul Gosain <agosain@luminanetworks.com>
(cherry picked from commit cedf67270d96f385d0c2154582c6ada267b0c005)

yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONNormalizedNodeStreamWriter.java
yang/yang-data-codec-gson/src/test/resources/bug8927/json/expected.json

index cb1097b43ffe2da1afe3d6528ca6c9a32ce13ff4..857badcd37f15d2d46d37928c94d4a1e4944499b 100644 (file)
@@ -274,10 +274,9 @@ public final class JSONNormalizedNodeStreamWriter implements NormalizedNodeStrea
 
     private void writeXmlValue(final Node node) throws IOException {
         Text firstChild = getFirstChildText(node);
+        String childNodeText = firstChild != null ? firstChild.getWholeText() : "";
+        childNodeText = childNodeText != null ? childNodeText.trim() : "";
 
-        final String childNodeText = firstChild!=null
-                ? (firstChild.getWholeText()!=null ? firstChild.getWholeText().trim() : null)
-                : "null";
         if (NUMBER_PATTERN.matcher(childNodeText).matches()) {
             writer.value(parseNumber(childNodeText));
             return;
index b230c30a8653470bd298f7fe360d6ff747f55e88..e491fe3b426bc6df90bdcfbc596c2ea5c5f67d5c 100644 (file)
@@ -2,7 +2,7 @@
   "bug8927:foo": {
     "alarm-information": {
       "alarm-summary": {
-        "active-alarm-count": null
+        "active-alarm-count": ""
       },
       "alarm-detail": {
         "alarm-time": "2017-08-02 19:03:44 UTC",
       }
     }
   }
-}
\ No newline at end of file
+}