Open OlehHoliuk opened 2 years ago
Seeing the same error after updating from 2.4.0 to 2.7.0 to resolve some vulnerabilities.
I pinpointed the issue to this method: https://github.com/json-path/JsonPath/blob/8cdaaef9009b0dd0d9335ffb1ccbe03b7fe8a586/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L748-L760
For GsonJsonProvider
, the createArray
method returns a JsonArray
.
https://github.com/json-path/JsonPath/blob/8cdaaef9009b0dd0d9335ffb1ccbe03b7fe8a586/json-path/src/main/java/com/jayway/jsonpath/spi/json/GsonJsonProvider.java#L144
The caller (https://github.com/json-path/JsonPath/blob/8cdaaef9009b0dd0d9335ffb1ccbe03b7fe8a586/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L280) is generic and just returns the result.
The caller to that (https://github.com/json-path/JsonPath/blob/8cdaaef9009b0dd0d9335ffb1ccbe03b7fe8a586/json-path%2Fsrc%2Fmain%2Fjava%2Fcom%2Fjayway%2Fjsonpath%2Finternal%2FJsonContext.java#L159) expects a List<String>
.
I am using
GsonJsonProvider
and it returnsJsonArray
fromcreateArray
method.JsonArray
is not implementingList
interface, butIterable
. This body of delete method inJsonContext
expects to receiveList
and notIterable
:Context: I am calling delete method on multiple json objects, and some of them may not contain nodes that I want to delete. I am using
Option.SUPPRESS_EXCEPTIONS
for this case. And when there is no such path in my object it is fallbacks to the recently addedJsonPath#handleMissingPathInContext(configuration)
method, which returnconfiguration.jsonProvider().createArray()
(theJsonArray
) and delete method fails with java.lang.ClassCastException: class com.google.gson.JsonArray cannot be cast to class java.util.List