From 09705266013bdc54b58a8b9791de897aafdf4b8c Mon Sep 17 00:00:00 2001 From: sb5356 Date: Fri, 15 Jun 2018 16:20:12 -0400 Subject: 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 --- .../ccsdk/sli/plugins/restapicall/XmlJsonUtil.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'restapi-call-node/provider/src/main') 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 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"); -- cgit 1.2.3-korg