diff options
author | Dan Timoney <dt5972@att.com> | 2018-06-22 21:08:02 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-06-22 21:08:02 +0000 |
commit | ee1a5318d57e8ab435ef2f298b999642ae9143f4 (patch) | |
tree | 3cf7e06288906eacf20bd0214622d6f1e86cc52b /restapi-call-node/provider | |
parent | 7ef4659e0b07164402cf6d7aa89b45df03063669 (diff) | |
parent | 09705266013bdc54b58a8b9791de897aafdf4b8c (diff) |
Merge "Capability to avoid surrounding values with quotes"
Diffstat (limited to 'restapi-call-node/provider')
2 files changed, 23 insertions, 7 deletions
diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java index 965d3daaa..8a0ca8d94 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java @@ -55,8 +55,14 @@ public final class XmlJsonUtil { escape = false; } + boolean quotes = true; + if (var.startsWith("\"")) { + var = var.substring(1); + quotes = false; + } + Object o = createStructure(varmap, var); - return generateJson(o, escape); + return generateJson(o, escape, quotes); } private static Object createStructure(Map<String, String> flatmap, String var) { @@ -159,22 +165,26 @@ public final class XmlJsonUtil { return null; } - private static String generateJson(Object o, boolean escape) { + private static String generateJson(Object o, boolean escape, boolean quotes) { if (o == null) return null; StringBuilder ss = new StringBuilder(); - generateJson(ss, o, 0, false, escape); + generateJson(ss, o, 0, false, escape, quotes); return ss.toString(); } @SuppressWarnings("unchecked") - private static void generateJson(StringBuilder ss, Object o, int indent, boolean padFirst, boolean escape) { + private static void generateJson(StringBuilder ss, Object o, int indent, boolean padFirst, boolean escape, boolean quotes) { if (o instanceof String) { String s = escape ? escapeJson((String) o) : (String) o; if (padFirst) ss.append(pad(indent)); - ss.append('"').append(s).append('"'); + if (quotes) { + ss.append('"').append(s).append('"'); + } else { + ss.append(s); + } return; } @@ -193,7 +203,7 @@ public final class XmlJsonUtil { Object v = entry.getValue(); String key = entry.getKey(); ss.append(pad(indent + 1)).append('"').append(key).append("\": "); - generateJson(ss, v, indent + 1, false, escape); + generateJson(ss, v, indent + 1, false, escape, true); } ss.append("\n"); @@ -215,7 +225,7 @@ public final class XmlJsonUtil { ss.append(",\n"); first = false; - generateJson(ss, o1, indent + 1, true, escape); + generateJson(ss, o1, indent + 1, true, escape, quotes); } ss.append("\n"); diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java index 579d194d5..fcbd844fc 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java @@ -144,6 +144,12 @@ public class TestXmlJsonUtil { ss = XmlJsonUtil.getJson(mm, "service-data.vnf-config-information"); log.info(ss); + + ss = XmlJsonUtil.getJson(mm, "service-data.vnf-config-information.vnf-host-ip-address"); + log.info(ss); + + ss = XmlJsonUtil.getJson(mm, "\"service-data.vnf-config-information.vnf-host-ip-address"); + log.info(ss); } @Test |