Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONPath$Filter


import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_access_filter_in_string extends TestCase {

    public void test_list_in() throws Exception {
        JSONPath path = new JSONPath("[name in ('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(1004, null));

        List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(1, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
    }
View Full Code Here


        Assert.assertEquals(1, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
    }
   
    public void test_list_not_in() throws Exception {
        JSONPath path = new JSONPath("[name not in ('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(1004, 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));
    }
View Full Code Here

        Assert.assertSame(entities.get(2), result.get(1));
        Assert.assertSame(entities.get(3), result.get(2));
    }
   
    public void test_list_in_2() throws Exception {
        JSONPath path = new JSONPath("[name in ('ljw2083', 'yakolee')]");
       
        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(1004, 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));
    }
View Full Code Here

        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(2), result.get(1));
    }
   
    public void test_list_in_3() throws Exception {
        JSONPath path = new JSONPath("[name in ('ljw2083', 'yakolee',null)]");
       
        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(1004, null));
       
        List<Object> result = (List<Object>) path.eval(entities);
        Assert.assertEquals(3, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(2), result.get(1));
        Assert.assertSame(entities.get(3), result.get(2));
    }
View Full Code Here

import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_wildcard extends TestCase {

    public void test_list_map() 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));
    }
View Full Code Here

        Assert.assertSame(entity.getId(), fieldValues.get(0));
        Assert.assertSame(entity.getName(), fieldValues.get(1));
    }
   
    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));
    }
View Full Code Here

    public void test_list_map() throws Exception {
        List list = new ArrayList();
        list.add(new Object());
        list.add(new Object());
        list.add(new Object());
        JSONPath path = new JSONPath("$.size()");
        Integer result = (Integer) path.eval(list);
        Assert.assertEquals(list.size(), result.intValue());
    }
View Full Code Here

    public void test_list_map() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("val", new Object());
        List list = new ArrayList();
        list.add(map);
        Assert.assertSame(map.get("val"), new JSONPath("$[0].val").eval(list));
        Assert.assertSame(map.get("val"), new JSONPath("$[-1].val").eval(list));
    }
View Full Code Here

import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_access_filter_notNull extends TestCase {

    public void test_list_map() throws Exception {
        JSONPath path = new JSONPath("$[?(@.name)]");

        List<Entity> entities = new ArrayList<Entity>();
        entities.add(new Entity(1001, "ljw2083"));
        entities.add(new Entity(1002, "wenshao"));
        entities.add(new Entity(1003, 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));
    }
View Full Code Here

public class JSONPath_none_root extends TestCase {

    public void test_root() throws Exception {
        List<Object> list = new ArrayList<Object>();
        list.add(new Object());
        Assert.assertSame(list.get(0), new JSONPath("[0]").eval(list));
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.JSONPath$Filter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.