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

Loading…
Cancel
Save