Search in sources :

Example 66 with JSONPath

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

the class JSONPath_field_access_filter_compare_string method test_list_eq_x.

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

Example 67 with JSONPath

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

the class JSONPath_field_access_filter_compare_string_simple method test_list_eq_null.

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

Example 68 with JSONPath

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

the class JSONPath_field_access_filter_compare_string_simple method test_list_le.

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

Example 69 with JSONPath

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

the class JSONPath_field_access_filter_compare_string_simple method test_list_lt.

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

Example 70 with JSONPath

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

the class JSONPath_field_access_filter_compare_string_simple method test_list_gt.

public void test_list_gt() throws Exception {
    JSONPath path = new JSONPath("$[name > '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(1), result.get(0));
}
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