json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.89k stars 1.64k forks source link

Issue with Version 2.8 - JsonPath.java#set() and JsonPath.java#add() #977

Open suhailSj opened 9 months ago

suhailSj commented 9 months ago

set/add method evaluates the path and if not present throws the error, ideally this should not be the case. ideally set sets the field on the desired path. In case of nested fields we should be verifying till the parent node only.

This change is breaking the code where we are setting the field in json using set method.

EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration, true);
        if (evaluationContext.getPathList().isEmpty()) {
            boolean optSuppressExceptions = configuration.containsOption(Option.SUPPRESS_EXCEPTIONS);
            if (optSuppressExceptions) {
                return handleMissingPathInContext(configuration);
            } else {
                throw new PathNotFoundException();
            }
        }

either we should remove if or we should only check till parent element. as this check is defying the functionality of set method. Suggestions please.

suhailSj commented 9 months ago

If admin confirms to this change i will raise a new CR and remove this check from #add method.

akanshSirohi commented 8 months ago

@suhailSj I am stucked on this kind of issue already, please check and let me know if you faced this issue or know the solution. https://github.com/json-path/JsonPath/issues/982#issue-2082624079