Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONPath


    public void test_put_array_long() throws Exception {
        Map<String, Object> root = new HashMap<String, Object>();
        root.put("values", new long[0]);

        JSONPath path = new JSONPath("$.values");
        path.arrayAdd(root, 123);

        long[] array = (long[]) root.get("values");
        Assert.assertEquals(1, array.length);
        Assert.assertEquals(123, array[0]);
    }
View Full Code Here


public class JSONPath_field_access_multi extends TestCase {

    public void test_list_map() throws Exception {
        Entity entity = new Entity(123, "wenshao");
        JSONPath path = new JSONPath("$['id','name']");
       
        List<Object> result = (List<Object>) path.eval(entity);
        Assert.assertSame(entity.getId(), result.get(0));
        Assert.assertSame(entity.getName(), result.get(1));
    }
View Full Code Here

import com.alibaba.fastjson.JSONPath;

public class JSONPath_field_access_filter_in_int extends TestCase {

    public void test_list_in() throws Exception {
        JSONPath path = new JSONPath("[id in (1001)]");

        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("[id not in (1001)]");

        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_not_in_null() throws Exception {
        JSONPath path = new JSONPath("[id not in (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(4, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
        Assert.assertSame(entities.get(1), result.get(1));
        Assert.assertSame(entities.get(2), result.get(2));
        Assert.assertSame(entities.get(3), result.get(3));
View Full Code Here

        Assert.assertSame(entities.get(2), result.get(2));
        Assert.assertSame(entities.get(3), result.get(3));
    }
   
    public void test_list_in_2() throws Exception {
        JSONPath path = new JSONPath("[id in (1001, 1003)]");
       
        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("[id in (1001, 1003, 1004)]");
       
        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

        Assert.assertSame(entities.get(2), result.get(1));
        Assert.assertSame(entities.get(3), result.get(2));
    }
   
    public void test_list_in_3_null() throws Exception {
        JSONPath path = new JSONPath("[id in (1001, 1003, 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(null, 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_access_filter_compare_string_simple extends TestCase {

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

        Assert.assertEquals(1, result.size());
        Assert.assertSame(entities.get(0), result.get(0));
    }
   
    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));
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.JSONPath

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.