use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_array_put method test_put_array_error_1.
public void test_put_array_error_1() throws Exception {
Exception error = null;
try {
JSONPath path = new JSONPath("$.values");
path.arrayAdd(Collections.singletonMap("values", new Object()), 123);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_access method test_list_map.
public void test_list_map() throws Exception {
Entity entity = new Entity(123, "wenshao");
JSONPath path = new JSONPath("$['id']");
Assert.assertSame(entity.getId(), path.eval(entity));
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_access_filter_compare_int method test_list_map_le.
public void test_list_map_le() throws Exception {
JSONPath path = new JSONPath("$[?(@.id <= 1002)]");
List<Object> result = (List<Object>) path.eval(entities);
Assert.assertEquals(2, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Assert.assertSame(entities.get(1), result.get(1));
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_field_access_filter_rlike method test_list_not_like_extract.
public void test_list_not_like_extract() throws Exception {
JSONPath path = new JSONPath("$[name not rlike 'wenshao']");
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(2, result.size());
Assert.assertSame(entities.get(0), result.get(0));
Assert.assertSame(entities.get(2), result.get(1));
}
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_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());
}
Aggregations