Browse Source

Update ValueNode.java

pull/314/head
jochenberger 7 years ago committed by GitHub
parent
commit
6cf30fd1a0
  1. 27
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java

27
json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java

@ -318,11 +318,11 @@ public abstract class ValueNode {
@Override
public Class<?> type(Predicate.PredicateContext ctx) {
if(ctx.configuration().jsonProvider().isArray(parse(ctx))) return List.class;
else if(ctx.configuration().jsonProvider().isMap(parse(ctx))) return Map.class;
else if(ctx.configuration().jsonProvider().unwrap(parse(ctx)) instanceof Number) return Number.class;
else if(ctx.configuration().jsonProvider().unwrap(parse(ctx)) instanceof String) return String.class;
else if(ctx.configuration().jsonProvider().unwrap(parse(ctx)) instanceof Boolean) return Boolean.class;
if(isArray(ctx)) return List.class;
else if(isMap(ctx)) return Map.class;
else if(parse(ctx) instanceof Number) return Number.class;
else if(parse(ctx) instanceof String) return String.class;
else if(parse(ctx) instanceof Boolean) return Boolean.class;
else return Void.class;
}
@ -338,11 +338,7 @@ public abstract class ValueNode {
if(!isArray(ctx)){
return UNDEFINED;
} else {
Collection nodes = new ArrayList();
for (Object value : ctx.configuration().jsonProvider().toIterable(parse(ctx))) {
nodes.add(value);
}
return new ValueListNode(nodes);
return new ValueListNode(Collections.unmodifiableList((List) parse(ctx)));
}
}
@ -363,19 +359,20 @@ public abstract class ValueNode {
}
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().isArray(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)) return ((List) parse(ctx)).size() == 0;
else if (isMap(ctx)) return ((Map) parse(ctx)).size() == 0;
else if((parse(ctx) instanceof String)) return ((String)parse(ctx)).length() == 0;
return true;
}
@ -850,4 +847,4 @@ public abstract class ValueNode {
}
}
}

Loading…
Cancel
Save