karate
karate copied to clipboard
nested array JSON building fails edge case
as reported here: https://stackoverflow.com/a/69536418/143475
to replicate the issue:
* def foo = {}
* set foo.a[0].b[0].c = 'hello'
* print foo
error:
* set foo.a[0].b[0].c = 'hello'
class java.util.LinkedHashMap cannot be cast to class java.util.List (java.util.LinkedHashMap and java.util.List are in module java.base of loader 'bootstrap')
workaround:
* def foo = {}
* set foo.a[0].b = [{ c: 'hello' }]
* print foo
Karate tries to auto-create missing parents and the logic is a bit tricky. you can find the code here: https://github.com/karatelabs/karate/blob/v1.1.0/karate-core/src/main/java/com/intuit/karate/Json.java#L141
@ptrthomas Can i work on this issue??
@sc2776 yes, go ahead
Hi @ptrthomas , Requesting more info on this. Can I get some sample java test cases for this issue if possible?
I did some analysis and came up with the sample request. Confirm if the below test case is one of the error scenarios.
Json json = Json.object(); json.set("first",""); json.set("first.second[0].third[0].fourth","hello");
Thanks
@captainbkarthick that looks correct, if you get the same error mentioned in the original post, you are on the right track
@ptrthomas, I am trying to solve this issue. Will keep you posted on this. Thanks
@ptrthomas , I have fixed the issue. Requesting to check the PR.
1.3.0 released