From: sb5356 Date: Fri, 15 Jun 2018 20:20:12 +0000 (-0400) Subject: Capability to avoid surrounding values with quotes X-Git-Tag: 0.3.0~29^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F91%2F54991%2F1;p=ccsdk%2Fsli%2Fplugins.git Capability to avoid surrounding values with quotes Restapi-call-node: Give opportunity for developer to specify a variable in a JSON template, so that restapi-call-node will know it should not surround the value with quotes. Change-Id: I844a8fd68f3015cbd6f5b039b8911e903de557ea Issue-ID: CCSDK-296 Signed-off-by: Stan Bonev --- 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 965d3daa..8a0ca8d9 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 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 579d194d..fcbd844f 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