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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations