Search in sources :

Example 21 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_list_size_3 method test_java_bean.

public void test_java_bean() throws Exception {
    Model model = new Model();
    model.id = 1001;
    model.name = "wenshao";
    JSONPath path = new JSONPath("$.size()");
    Integer result = (Integer) path.eval(model);
    Assert.assertEquals(2, result.intValue());
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath)

Example 22 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_object_filter method test_object_filter.

public void test_object_filter() throws Exception {
    JSONPath path = new JSONPath("[id=123]");
    Entity entity = new Entity(123, "ljw2083");
    Assert.assertSame(entity, path.eval(entity));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath)

Example 23 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_field_access_filter_like_simple method test_list_like_not_contains.

public void test_list_like_not_contains() throws Exception {
    JSONPath path = new JSONPath("$[name not like '%208%']");
    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(1), result.get(0));
    Assert.assertSame(entities.get(2), result.get(1));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 24 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_field_access_filter_like_simple method test_list_like_contains.

public void test_list_like_contains() throws Exception {
    JSONPath path = new JSONPath("$[name like '%208%']");
    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));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 25 with JSONPath

use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.

the class JSONPath_field_access_filter_like_simple method test_list_not_like_extract.

public void test_list_not_like_extract() throws Exception {
    JSONPath path = new JSONPath("$[name not 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, "yakolee"));
    entities.add(new Entity(null, null));
    List<Object> result = (List<Object>) path.eval(entities);
    Assert.assertEquals(3, result.size());
    Assert.assertSame(entities.get(1), result.get(0));
    Assert.assertSame(entities.get(2), result.get(1));
    Assert.assertSame(entities.get(3), result.get(2));
}
Also used : JSONPath(com.alibaba.fastjson.JSONPath) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

JSONPath (com.alibaba.fastjson.JSONPath)96 List (java.util.List)77 ArrayList (java.util.ArrayList)76 HashMap (java.util.HashMap)6 JSONException (com.alibaba.fastjson.JSONException)2 Entity (com.alibaba.json.bvt.path.JSONPath_between_int.Entity)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1