From 94b69866d249aa90def88f397fba016ac858e866 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 9 Oct 2020 13:56:16 +0200 Subject: [PATCH] read simple values from json --- src/com/sap/piper/analytics/InfluxData.groovy | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/com/sap/piper/analytics/InfluxData.groovy b/src/com/sap/piper/analytics/InfluxData.groovy index b9b103327..53467519b 100644 --- a/src/com/sap/piper/analytics/InfluxData.groovy +++ b/src/com/sap/piper/analytics/InfluxData.groovy @@ -58,8 +58,19 @@ class InfluxData implements Serializable{ def value if (name.endsWith(".json")){ name = name.replace(".json","") - script.echo "found JSON content: " + fileContent - value = script.readJSON(text: fileContent) + // net.sf.json.JSONSerializer does only handle lists and maps + // http://json-lib.sourceforge.net/apidocs/net/sf/json/package-summary.html + try{ + value = script.readJSON(text: fileContent) + }catch(net.sf.json.JSONException e){ + // try to wrap the value in an object and read again + if (e.getMessage() == "Invalid JSON String"){ + def JSONobject = readJSON(text: "{\"content\": ${fileContent}}") + value = JSONobject.content + }else{ + throw e + } + } }else{ // handle boolean values if(fileContent == 'true'){