Search in sources :

Example 86 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_list_size_1 method test_obj_array.

public void test_obj_array() throws Exception {
    Object[] array = new Object[] { 1, 2, 3 };
    JSONPath path = new JSONPath("$.size()");
    Integer result = (Integer) path.eval(array);
    Assert.assertEquals(array.length, result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath)

Example 87 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_list_size_1 method test_int_array.

public void test_int_array() throws Exception {
    int[] array = new int[] { 1, 2, 3 };
    JSONPath path = new JSONPath("$.size()");
    Integer result = (Integer) path.eval(array);
    Assert.assertEquals(array.length, result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath)

Example 88 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_list_size_2 method test_map.

public void test_map() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("1001", 1001);
    map.put("1002", 1002);
    JSONPath path = new JSONPath("$.size()");
    Integer result = (Integer) path.eval(map);
    Assert.assertEquals(map.size(), result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) HashMap(java.util.HashMap)

Example 89 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_list_size_2 method test_map_null.

public void test_map_null() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("1001", 1001);
    map.put("1002", 1002);
    map.put("1003", null);
    JSONPath path = new JSONPath("$.size()");
    Integer result = (Integer) path.eval(map);
    Assert.assertEquals(2, result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) HashMap(java.util.HashMap)

Example 90 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_list_size_3 method test_java_bean_field_null.

public void test_java_bean_field_null() throws Exception {
    Model model = new Model();
    model.id = 1001;
    model.name = null;
    JSONPath path = new JSONPath("$.size()");
    Integer result = (Integer) path.eval(model);
    Assert.assertEquals(1, result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath)

Aggregations

JSONPath (com.alibaba.fastjson.JSONPath)96 List (java.util.List)77 ArrayList (java.util.ArrayList)76 HashMap (java.util.HashMap)6 JSONException (com.alibaba.fastjson.JSONException)2 Entity (com.alibaba.json.bvt.path.JSONPath_between_int.Entity)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1