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