use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_access_filter_rlike method test_list_like_left_match.
public void test_list_like_left_match() throws Exception {
JSONPath path = new JSONPath("$[?(@.name like 'ljw%')]");
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_multi method test_list_map.
public void test_list_map() throws Exception {
Entity entity = new Entity(123, "wenshao");
JSONPath path = new JSONPath("$['id','name']");
List<Object> result = (List<Object>) path.eval(entity);
Assert.assertSame(entity.getId(), result.get(0));
Assert.assertSame(entity.getName(), result.get(1));
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_wildcard method test_list_map_none_root.
public void test_list_map_none_root() throws Exception {
JSONPath path = new JSONPath("*");
Entity entity = new Entity(123, "wenshao");
List<Object> fieldValues = (List<Object>) path.eval(entity);
Assert.assertSame(entity.getId(), fieldValues.get(0));
Assert.assertSame(entity.getName(), fieldValues.get(1));
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_wildcard method test_list_map.
public void test_list_map() throws Exception {
JSONPath path = new JSONPath("$.*");
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("id", 123);
map.put("name", "wenshao");
Collection<Object> fieldValues = (Collection<Object>) path.eval(map);
Iterator<Object> it = fieldValues.iterator();
Assert.assertSame(map.get("id"), it.next());
Assert.assertSame(map.get("name"), it.next());
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_list_field method test_list_field.
public void test_list_field() 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));
}
Aggregations