1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

read simple values from json

This commit is contained in:
Christopher Fenner 2020-10-09 13:56:16 +02:00
parent c009e99061
commit 94b69866d2
No known key found for this signature in database
GPG Key ID: 1D72FE34B3FECE9C

View File

@ -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'){