use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_access_filter_like method test_list_like_extract.
public void test_list_like_extract() throws Exception {
JSONPath path = new JSONPath("$[?(@.name like 'ljw2083')]");
List<Entity> entities = new ArrayList<Entity>();
entities.add(new Entity(1001, "ljw2083"));
entities.add(new Entity(1002, "wenshao"));
entities.add(new Entity(1003, null));
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_size method test_path_size_2.
public void test_path_size_2() throws Exception {
List list = new ArrayList();
list.add(new Entity(101, "kiki"));
list.add(new Entity(102, "ljw2083"));
list.add(new Entity(103, "ljw2083"));
JSONObject root = new JSONObject();
root.put("values", list);
JSONPath path = JSONPath.compile("$.values");
Assert.assertEquals(3, path.size(root));
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_size method test_path_size.
public void test_path_size() throws Exception {
JSONPath path = JSONPath.compile("$");
Assert.assertEquals(-1, path.size(null));
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_toString method test_toJSONString.
public void test_toJSONString() throws Exception {
Model model = new Model();
model.path = new JSONPath("$");
String text = JSON.toJSONString(model);
Assert.assertEquals("{\"path\":\"$\"}", text);
JSON.parseObject(text, Model.class);
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_list_range method test_range_step.
public void test_range_step() 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());
JSONPath path = new JSONPath("$[2:8:2]");
List<Object> result = (List<Object>) path.eval(list);
Assert.assertEquals(2, result.size());
Assert.assertSame(list.get(2), result.get(0));
Assert.assertSame(list.get(4), result.get(1));
}
Aggregations