use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_array_put method test_put.
public void test_put() throws Exception {
Map<String, Object> root = new HashMap<String, Object>();
List list = new ArrayList();
root.put("values", list);
JSONPath path = new JSONPath("$.values");
path.arrayAdd(root, 123);
path.arrayAdd(root, (Object[]) null);
path.arrayAdd(root, new Object[0]);
path.arrayAdd(null, new Object[] { 1 });
Assert.assertEquals(1, list.size());
Assert.assertEquals(123, ((Integer) list.get(0)).intValue());
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_access_filter_like_simple 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_field_access_filter_like_simple method test_list_like_match_two_segement.
public void test_list_like_match_two_segement() throws Exception {
JSONPath path = new JSONPath("$[name like 'ljw%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_like_simple method test_list_like_match_two_segement_2.
public void test_list_like_match_two_segement_2() throws Exception {
JSONPath path = new JSONPath("$[name like 'ljw%w2083']");
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(0, result.size());
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_access_filter_like_simple 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));
}
Aggregations