Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONObject


    public Object parseObject(final Map object) {
        return parseObject(object, null);
    }

    public JSONObject parseObject() {
        JSONObject object = new JSONObject();
        parseObject(object);
        return object;
    }
View Full Code Here


                    case FALSE:
                        value = Boolean.FALSE;
                        lexer.nextToken(JSONToken.COMMA);
                        break;
                    case LBRACE:
                        JSONObject object = new JSONObject();
                        value = parseObject(object, i);
                        break;
                    case LBRACKET:
                        Collection items = new JSONArray();
                        parseArray(items, i);
View Full Code Here

            case LBRACKET:
                JSONArray array = new JSONArray();
                parseArray(array, fieldName);
                return array;
            case LBRACE:
                JSONObject object = new JSONObject();
                return parseObject(object, fieldName);
            case LITERAL_INT:
                Number intValue = lexer.integerValue();
                lexer.nextToken();
                return intValue;
View Full Code Here

    public Object createInstance(DefaultJSONParser parser, Type type) {
        if (type instanceof Class) {
            if (clazz.isInterface()) {
                Class<?> clazz = (Class<?>) type;
                ClassLoader loader = Thread.currentThread().getContextClassLoader();
                final JSONObject obj = new JSONObject();
                Object proxy = Proxy.newProxyInstance(loader, new Class<?>[] { clazz }, obj);
                return proxy;
            }
        }
View Full Code Here

                    }
                }
            }

            if (clazz.isInterface()) {
                JSONObject object;

                if (map instanceof JSONObject) {
                    object = (JSONObject) map;
                } else {
                    object = new JSONObject(map);
                }

                return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                                                  new Class<?>[] { clazz }, object);
            }
View Full Code Here

       
        Map newMap;
        if (mapClass == HashMap.class) {
          newMap = new HashMap();
        } else if (mapClass == JSONObject.class) {
          newMap = new JSONObject();
        } else if (mapClass == LinkedHashMap.class) {
          newMap = new LinkedHashMap();
        } else if (mapClass == TreeMap.class) {
          newMap = new TreeMap();
        } else if (mapClass == AntiCollisionHashMap.class) {
View Full Code Here

        Assert.assertTrue(array.getJSONObject(0) == null);
    }

    public void test_getObject() throws Exception {
        JSONArray array = new JSONArray();
        array.add(new JSONObject());

        Assert.assertEquals(0, array.getJSONObject(0).size());
    }
View Full Code Here

public class MaterializedInterfaceTest2 extends TestCase {
   
    public void test_parse() throws Exception {
        String text = "{\"id\":123, \"name\":\"chris\"}";
        JSONObject object = JSON.parseObject(text);
       
        Bean bean = TypeUtils.cast(object, Bean.class, null);
       
        Assert.assertEquals(123, bean.getId());
        Assert.assertEquals("chris", bean.getName());
View Full Code Here

import com.alibaba.fastjson.JSONObject;

public class JSONObjectTest_hashCode extends TestCase {

    public void test_hashCode() throws Exception {
        Assert.assertEquals(new JSONObject().hashCode(), new JSONObject().hashCode());
    }
View Full Code Here

import com.alibaba.fastjson.serializer.SerializerFeature;

public class TabCharTest extends TestCase {

    public void test_0() throws Exception {
        JSONObject json = new JSONObject();
        json.put("hello\t", "World\t!");
        Assert.assertEquals("{\"hello\\t\":\"World\\t!\"}", JSON.toJSONString(json));
        Assert.assertEquals("{hello\t:\"World\t!\"}", JSON.toJSONStringZ(json, SerializeConfig.getGlobalInstance()));
        Assert.assertEquals("{'hello\\t':'World\\t!'}", JSON.toJSONString(json, SerializerFeature.WriteTabAsSpecial, SerializerFeature.UseSingleQuotes));
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.JSONObject

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.