Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public <T> T set(Object jsonObject, Object newVal, Configuration configuration)
if (evaluationContext.getPathList().isEmpty()) {
boolean optSuppressExceptions = configuration.containsOption(Option.SUPPRESS_EXCEPTIONS);
if (optSuppressExceptions) {
return handleMissingPathInContext(configuration);
return resultByConfiguration(handleMissingPathInContext(configuration), configuration, evaluationContext);
} else {
throw new PathNotFoundException();
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public <T> T map(Object jsonObject, MapFunction mapFunction, Configuration confi
if (evaluationContext.getPathList().isEmpty()) {
boolean optSuppressExceptions = configuration.containsOption(Option.SUPPRESS_EXCEPTIONS);
if (optSuppressExceptions) {
return handleMissingPathInContext(configuration);
return resultByConfiguration(handleMissingPathInContext(configuration), configuration, evaluationContext);
} else {
throw new PathNotFoundException();
}
Expand All @@ -277,7 +277,7 @@ public <T> T delete(Object jsonObject, Configuration configuration) {
if (evaluationContext.getPathList().isEmpty()) {
boolean optSuppressExceptions = configuration.containsOption(Option.SUPPRESS_EXCEPTIONS);
if (optSuppressExceptions) {
return handleMissingPathInContext(configuration);
return resultByConfiguration(handleMissingPathInContext(configuration), configuration, evaluationContext);
} else {
throw new PathNotFoundException();
}
Expand All @@ -304,7 +304,7 @@ public <T> T add(Object jsonObject, Object value, Configuration configuration) {
if (evaluationContext.getPathList().isEmpty()) {
boolean optSuppressExceptions = configuration.containsOption(Option.SUPPRESS_EXCEPTIONS);
if (optSuppressExceptions) {
return handleMissingPathInContext(configuration);
return resultByConfiguration(handleMissingPathInContext(configuration), configuration, evaluationContext);
} else {
throw new PathNotFoundException();
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public <T> T put(Object jsonObject, String key, Object value, Configuration conf
if (evaluationContext.getPathList().isEmpty()) {
boolean optSuppressExceptions = configuration.containsOption(Option.SUPPRESS_EXCEPTIONS);
if (optSuppressExceptions) {
return handleMissingPathInContext(configuration);
return resultByConfiguration(handleMissingPathInContext(configuration), configuration, evaluationContext);
} else {
throw new PathNotFoundException();
}
Expand Down
18 changes: 18 additions & 0 deletions json-path/src/test/java/com/jayway/jsonpath/old/JsonPathTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.jayway.jsonpath.old;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.jayway.jsonpath.*;
import com.jayway.jsonpath.internal.path.PathCompiler;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -322,4 +327,17 @@ public void prevent_stack_overflow_error_when_unclosed_property() {
assertThrows(InvalidPathException.class, () -> JsonPath.compile("$['boo','foo][?(@ =~ /bar/)]"));
}

@Test
//see https://github.com/json-path/JsonPath/issues/1039
public void prevent_class_cast_exception_when_path_is_missing() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode document = (ObjectNode) objectMapper.readTree(DOCUMENT);
DocumentContext context = JsonPath.using(Configuration.builder()
.jsonProvider(new JacksonJsonNodeJsonProvider(objectMapper))
.mappingProvider(new JacksonMappingProvider(objectMapper))
.options(Option.SUPPRESS_EXCEPTIONS)
.build()).parse(document);
context.delete(JsonPath.compile("$.notExisting"));
}

}