Describe the bug
Using json.path.read() to retrieve numeric values from JSON objects returns a string.
For this source:
[h: j='{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } }, "expensive": 10 }']
This produces an error:
[r: res = json.path.read(j, "store.book[0].price")*0.70]
Illegal argument type java.lang.String, expecting java.math.BigDecimal
While this works:
[r: res = json.path.read(j, "store.book[0].price")]
[r: res * 0.70]
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Expected numeric values.
MapTool Info
Desktop (please complete the following information):
I didn't add an automatic conversion to BigDecimal like there is for getProperty and other functions.
At this point we might consider units tests, it is getting hard to keep track of every possibility. I would rather not play a game of whack-a-mole with this.
Yeah. My tests never used the returned value directly in a math operation like above so I didn't catch it before.
@cwisniew is in there doing some other JSON stuff so he's got this.
All of the json.path macros that return values are returning strings all the time which is incorrect.
On Top of this most of the JSON macro function class needs to be rewritten, the new json.path macros introduced yet another json parser/library and should have converted all the existing code if a new parsing method was going to be used.
There also hacks that have been made to address problems passing JSON outside of MapTool instead of addressing the issues.
The json.path functions also convert from internal json representation to string, then parse that string again.
For the rewrite of the JSON macro function class, did you consider converting all JSON elements to Gson? I think that might be the best solution.
For the rewrite of the JSON macro function class, did you consider converting all JSON elements to Gson? I think that might be the best solution.
Thats what I am doing
Awesome!
See also #775 .
Temp fix put in. Rework of class will go under a different issue for next release.
Closing.