Search in sources :

Example 16 with JSONPath

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

the class JSONPath_list_field method test_list_field_simple.

public void test_list_field_simple() throws Exception {
    JSONPath path = new JSONPath("name");
    List<Entity> entities = new ArrayList<Entity>();
    entities.add(new Entity("wenshao"));
    entities.add(new Entity("ljw2083"));
    List<String> names = (List<String>) path.eval(entities);
    Assert.assertSame(entities.get(0).getName(), names.get(0));
    Assert.assertSame(entities.get(1).getName(), names.get(1));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with JSONPath

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

the class JSONPath_list_range method test_range_2.

public void test_range_2() throws Exception {
    List list = new ArrayList();
    list.add(new Object());
    list.add(new Object());
    list.add(new Object());
    list.add(new Object());
    list.add(new Object());
    list.add(new Object());
    JSONPath path = new JSONPath("$[4:]");
    List<Object> result = (List<Object>) path.eval(list);
    Assert.assertEquals(2, result.size());
    Assert.assertSame(list.get(4), result.get(0));
    Assert.assertSame(list.get(5), result.get(1));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 18 with JSONPath

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

the class JSONPath_size method test_path_size_1.

public void test_path_size_1() throws Exception {
    List list = new ArrayList();
    list.add(new Entity(101, "kiki"));
    list.add(new Entity(102, "ljw2083"));
    list.add(new Entity(103, "ljw2083"));
    JSONPath path = JSONPath.compile("$");
    Assert.assertEquals(3, path.size(list));
}
Also used : Entity(com.alibaba.json.bvt.path.JSONPath_between_int.Entity) JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with JSONPath

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

the class JSONPath_list_size method test_list_size.

public void test_list_size() throws Exception {
    List list = new ArrayList();
    list.add(new Object());
    list.add(new Object());
    list.add(new Object());
    JSONPath path = new JSONPath("$.size()");
    Integer result = (Integer) path.eval(list);
    Assert.assertEquals(list.size(), result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 20 with JSONPath

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

the class JSONPath_list_size method test_list_size2.

public void test_list_size2() throws Exception {
    List list = new ArrayList();
    list.add(new Object());
    list.add(new Object());
    list.add(new Object());
    JSONPath path = new JSONPath("$.size");
    Integer result = (Integer) path.eval(list);
    Assert.assertEquals(list.size(), result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

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