diff options
author | 2018-06-15 16:20:12 -0400 | |
---|---|---|
committer | 2018-06-15 16:29:42 -0400 | |
commit | 09705266013bdc54b58a8b9791de897aafdf4b8c (patch) | |
tree | 702a038aa8ffbc9026a4ba45c2ab4d968311edbd /restapi-call-node/provider/src/main/java/org | |
parent | a87dc9c351b0c08d20adc428c215cf3934bb79bb (diff) |
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 <sb5356@att.com>
Diffstat (limited to 'restapi-call-node/provider/src/main/java/org')
-rw-r--r-- | restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java | 24 |
1 files changed, 17 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 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<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"); |