Search in sources :

Example 91 with JSONPath

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

the class JSONPath_object_filter method test_object_filter_not_match.

public void test_object_filter_not_match() throws Exception {
    JSONPath path = new JSONPath("[id=124]");
    Entity entity = new Entity(123, "ljw2083");
    Assert.assertNull(path.eval(entity));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath)

Example 92 with JSONPath

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

the class JSONPath_field_access_filter_rlike method test_list_like_match_two_segement_3.

public void test_list_like_match_two_segement_3() throws Exception {
    JSONPath path = new JSONPath("$[?(@.name like 'ljw%2%0%83')]");
    List<Entity> entities = new ArrayList<Entity>();
    entities.add(new Entity(1001, "ljw2083"));
    entities.add(new Entity(1002, "wenshao"));
    entities.add(new Entity(1003, "yakolee"));
    entities.add(new Entity(null, null));
    List<Object> result = (List<Object>) path.eval(entities);
    Assert.assertEquals(1, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 93 with JSONPath

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

the class JSONPath_field_access_filter_rlike method test_list_like_right_match.

public void test_list_like_right_match() throws Exception {
    JSONPath path = new JSONPath("$[?(@.name like '%2083')]");
    List<Entity> entities = new ArrayList<Entity>();
    entities.add(new Entity(1001, "ljw2083"));
    entities.add(new Entity(1002, "wenshao"));
    entities.add(new Entity(1003, "yakolee"));
    entities.add(new Entity(null, null));
    List<Object> result = (List<Object>) path.eval(entities);
    Assert.assertEquals(1, result.size());
    Assert.assertSame(entities.get(0), result.get(0));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 94 with JSONPath

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

the class JSONPath_list method test_list_map.

public void test_list_map() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("val", new Object());
    List list = new ArrayList();
    list.add(map);
    Assert.assertSame(map.get("val"), new JSONPath("$[0].val").eval(list));
    Assert.assertSame(map.get("val"), new JSONPath("$[-1].val").eval(list));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 95 with JSONPath

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

the class JSONPath_list_range method test_range_1.

public void test_range_1() 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());
    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(5, result.size());
    Assert.assertSame(list.get(0), result.get(0));
    Assert.assertSame(list.get(1), result.get(1));
    Assert.assertSame(list.get(2), result.get(2));
    Assert.assertSame(list.get(3), result.get(3));
    Assert.assertSame(list.get(4), result.get(4));
}
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