Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,19 @@ public Object getJson() {
}

public boolean isArray(Predicate.PredicateContext ctx) {
return ctx.configuration().jsonProvider().isArray(parse(ctx));
return parse(ctx) instanceof List;
}

public boolean isMap(Predicate.PredicateContext ctx) {
return ctx.configuration().jsonProvider().isMap(parse(ctx));
return parse(ctx) instanceof Map;
}

public int length(Predicate.PredicateContext ctx) {
return isArray(ctx) ? ctx.configuration().jsonProvider().length(parse(ctx)) : -1;
return isArray(ctx) ? ((List<?>) parse(ctx)).size() : -1;
}

public boolean isEmpty(Predicate.PredicateContext ctx) {
if (isArray(ctx) || isMap(ctx)) return ctx.configuration().jsonProvider().length(parse(ctx)) == 0;
if (isArray(ctx) || isMap(ctx)) return ((Collection<?>) parse(ctx)).size() == 0;
else if((parse(ctx) instanceof String)) return ((String)parse(ctx)).length() == 0;
return true;
}
Expand Down Expand Up @@ -844,8 +844,8 @@ public ValueNode evaluate(Predicate.PredicateContext ctx) {
else if (res instanceof String) return ValueNode.createStringNode(res.toString(), false);
else if (res instanceof Boolean) return ValueNode.createBooleanNode(res.toString());
else if (res == null) return ValueNode.NULL_NODE;
else if (ctx.configuration().jsonProvider().isArray(res)) return ValueNode.createJsonNode(res);
else if (ctx.configuration().jsonProvider().isMap(res)) return ValueNode.createJsonNode(res);
else if (ctx.configuration().jsonProvider().isArray(res)) return ValueNode.createJsonNode(ctx.configuration().mappingProvider().map(res, List.class, ctx.configuration()));
else if (ctx.configuration().jsonProvider().isMap(res)) return ValueNode.createJsonNode(ctx.configuration().mappingProvider().map(res, Map.class, ctx.configuration()));
else throw new JsonPathException("Could not convert " + res.toString() + " to a ValueNode");
} catch (PathNotFoundException e) {
return ValueNode.UNDEFINED;
Expand Down
28 changes: 28 additions & 0 deletions json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import com.jayway.jsonpath.internal.Utils;
import com.jayway.jsonpath.spi.cache.LRUCache;
import com.jayway.jsonpath.spi.json.GsonJsonProvider;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.mapper.GsonMappingProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingException;
import net.minidev.json.JSONAware;
import net.minidev.json.parser.JSONParser;
Expand Down Expand Up @@ -1019,4 +1021,30 @@ public void issue_309(){
assertThat(doc.read("$.jsonArr[0].name")).isEqualTo("nOne");
assertThat(doc.read("$.jsonArr[1].name")).isEqualTo("Jayway");
}

@Test
public void issue_378(){

String json = "{\n" +
" \"nodes\": {\n" +
" \"unnamed1\": {\n" +
" \"ntpServers\": [\n" +
" \"1.2.3.4\"\n" +
" ]\n" +
" }\n" +
" }\n" +
"}";

Configuration configuration = Configuration.builder()
.jsonProvider(new JacksonJsonNodeJsonProvider())
.mappingProvider(new JacksonMappingProvider())
.build();

DocumentContext ctx = JsonPath.using(configuration).parse(json);

String path = "$.nodes[*][?(!([\"1.2.3.4\"] subsetof @.ntpServers))].ntpServers";
JsonPath jsonPath = JsonPath.compile(path);

ctx.read(jsonPath);
}
}