Browse Source

changed JSONArray -> interface Collection to catch all use-cases

pull/103/head
Matt Greenwood 10 years ago
parent
commit
f76d556fb6
  1. 9
      json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java

9
json-path/src/main/java/com/jayway/jsonpath/internal/function/Length.java

@ -5,9 +5,7 @@ import com.jayway.jsonpath.internal.EvaluationContext;
import com.jayway.jsonpath.internal.PathRef; import com.jayway.jsonpath.internal.PathRef;
import net.minidev.json.JSONArray; import net.minidev.json.JSONArray;
import java.util.HashMap; import java.util.*;
import java.util.LinkedHashMap;
import java.util.Map;
/** /**
* Provides the length of a JSONArray Object * Provides the length of a JSONArray Object
@ -18,9 +16,8 @@ public class Length implements Function {
@Override @Override
public Object invoke(String currentPath, PathRef parent, Object model, EvaluationContext ctx) { public Object invoke(String currentPath, PathRef parent, Object model, EvaluationContext ctx) {
if (model instanceof JSONArray) { if (model instanceof Collection) {
JSONArray array = (JSONArray)model; return Integer.valueOf(((Collection) model).size());
return Integer.valueOf(array.size());
} }
else if (model instanceof Map) { else if (model instanceof Map) {
return Integer.valueOf(((Map) model).size()); return Integer.valueOf(((Map) model).size());

Loading…
Cancel
Save