Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONPath$Filter


import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_access_filter_compare_int_simple extends TestCase {

    public void test_list() throws Exception {
        JSONPath path = new JSONPath("$[id <= 1002]");

        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));
    }
View Full Code Here


        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(1), result.get(1));
    }

    public void test_list_2() throws Exception {
        JSONPath path = new JSONPath("[id <= 1002]");

        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));
    }
View Full Code Here

import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_access_filter_compare_int extends TestCase {

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

        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));
    }
View Full Code Here

public class JSONPath_0 extends TestCase {

    public void test_root() throws Exception {
        Object obj = new Object();
        Assert.assertSame(obj, new JSONPath("$").eval(obj));
    }
View Full Code Here

        Object obj = new Object();
        Assert.assertSame(obj, new JSONPath("$").eval(obj));
    }

    public void test_null() throws Exception {
        Assert.assertNull(new JSONPath("$").eval(null));
    }
View Full Code Here

    }

    public void test_map() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("val", new Object());
        Assert.assertSame(map.get("val"), new JSONPath("$.val").eval(map));
    }
View Full Code Here

    }
   
    public void test_entity() throws Exception {
        Entity entity = new Entity();
        entity.setValue(new Object());
        Assert.assertSame(entity.getValue(), new JSONPath("$.value").eval(entity));
    }
View Full Code Here

import com.alibaba.fastjson.JSONPath;

public class JSONPath_list_field extends TestCase {

    public void test_list_field() throws Exception {
        JSONPath path = new JSONPath("$.name");
        List<Entity> entities = new ArrayList<Entity>();
        entities.add(new Entity("wenshao"));
        entities.add(new Entity("ljw2083"));

        List<String> names = (List<String>)path.eval(entities);
        Assert.assertSame(entities.get(0).getName(), names.get(0));
        Assert.assertSame(entities.get(1).getName(), names.get(1));
    }
View Full Code Here

        Assert.assertSame(entities.get(0).getName(), names.get(0));
        Assert.assertSame(entities.get(1).getName(), names.get(1));
    }
   
    public void test_list_field_simple() throws Exception {
        JSONPath path = new JSONPath("name");
       
        List<Entity> entities = new ArrayList<Entity>();
        entities.add(new Entity("wenshao"));
        entities.add(new Entity("ljw2083"));
       
        List<String> names = (List<String>) path.eval(entities);
        Assert.assertSame(entities.get(0).getName(), names.get(0));
        Assert.assertSame(entities.get(1).getName(), names.get(1));
    }
View Full Code Here

import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_access_filter_like extends TestCase {

    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));
    }
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.