Hello,
I have a strange problem with my step result processing.
I have a step ("get all devices") that can return a list of devices. the result is always ["item1", "item2, ...] etc, even if I have only one item.
In a further step, I get this step's output and do a parsing :
items_list = jsonSlurper.parseText(items_list)
this works fine. I use this as the items can sometimes be listed as [{"uid1":"item1"}],etc.
The problem is that it sometimes fails because my input is incorrect.
If my first step provides me with two items or more ( ["item1", "item2, ...] ) the second step input (${get all devices#testResponse#$['result']}) gives me ["item1", "item2, ...]
If my first step provides me with a single item (["item1]) the second step input is like [item1] => slight difference, but with the missing "" my json parsing fails
Does anyone knows why the format changes ?
Solved! Go to Solution.
I found a workaround, though I really would like to know why this happens.
Here is the workaround :
if (items_list.tokenize('[,]').size() == 1) { items_list = groovy.json.JsonOutput.toJson(items_list.tokenize('[,]')) } items_list = jsonSlurper.parseText(items_list)
[item1] becomes ["item1"] and can be parsed properly
I found a workaround, though I really would like to know why this happens.
Here is the workaround :
if (items_list.tokenize('[,]').size() == 1) { items_list = groovy.json.JsonOutput.toJson(items_list.tokenize('[,]')) } items_list = jsonSlurper.parseText(items_list)
[item1] becomes ["item1"] and can be parsed properly
Thanks for sharing the solution with us!
I'm sure it will help someone in the future.
User | Count |
---|---|
7 | |
6 | |
6 | |
2 | |
1 |
Subject | Author | Latest Post |
---|---|---|