0

I am using version 2.4.0 of the com.jayway.jsonpath json-path library. I have attempting to parse an invalid document, but I done't get an exception thrown. The code is like

this.json= Configuration.defaultConfiguration().jsonProvider().parse(document);

The value of the document variable passed into the parse method is "notvalidjson". However the call returns fine assigning the string "notvalidjson" to the member json Object. Is this expected behaviour> I was expecting an InvalidJsonException to be thrown.

Thanks, Paul

ceepan
  • 87
  • 2
  • 8
  • By default this configuration will use the `JsonSmartJsonProvider`, which according to my experience does not report failures back at parse time but on evaluation time (when you attempt to access the property). You can try to use `JacksonJsonProvider` instead (or `GsonJsonProvider`) which threw an exception already on parse time – Roman Vottner Feb 18 '19 at 13:24
  • Thanks for the quik reply. I am in the process of attempting to use the JacksonJsonProvider. However I am seeing an issue that I wasn't when using the default JsonSmartJsonProvider. I get a ClassCastException with message "java.util.ArrayList cannot be cast to net.minidev.json.JSONArray" if I attempt to do JSONArray res = JsonPath.read(document, selector); The document is a LinkedHashMap as returned as above. – ceepan Feb 18 '19 at 13:39
  • Managed to fix this rather than using JSONArray res = JsonPath.read(document, selector); I have used JSONArray res = JsonPath.parse(document).read(selector, JSONArray.class); – ceepan Feb 18 '19 at 14:21

1 Answers1

0

Managed to fix this rather than using JSONArray res = JsonPath.read(document, selector); I have used JSONArray res = JsonPath.parse(document).read(selector, JSONArray.class)

ceepan
  • 87
  • 2
  • 8