Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONObject


    public void test_utf_4() throws Exception {
        ThreadLocalCache.clearChars();
       
        byte[] bytes = decodeHex("C2FF".toCharArray());
        String content = new String(bytes, "UTF-8");
        JSONObject json = new JSONObject();
        json.put("content", content);
        JSONObject obj = (JSONObject) JSON.parse(json.toJSONString().getBytes("UTF-8"));
        Assert.assertEquals(1, obj.size());
        Assert.assertEquals(content, obj.get("content"));
    }
View Full Code Here


    }

    public void test_writeTo_0() throws Exception {
        SerializeWriter out = new SerializeWriter();

        JSONObject json = new JSONObject();
        json.writeJSONString(out);

        Assert.assertEquals("{}", out.toString());
    }
View Full Code Here

    }

    public void test_writeTo_1() throws Exception {
        StringWriter out = new StringWriter();

        JSONObject json = new JSONObject();
        json.writeJSONString(out);

        Assert.assertEquals("{}", out.toString());
    }
View Full Code Here

    }

    public void test_writeTo_2() throws Exception {
        StringBuffer out = new StringBuffer();

        JSONObject json = new JSONObject();
        json.writeJSONString(out);

        Assert.assertEquals("{}", out.toString());
    }
View Full Code Here

    }

    public void test_writeTo_error() throws Exception {
        JSONException error = null;
        try {
            JSONObject json = new JSONObject();
            json.writeJSONString(new ErrorAppendable());
        } catch (JSONException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

        }
        Assert.assertNotNull(error);
    }

    public void test_exception() throws Exception {
        JSONObject object = (JSONObject) JSON.toJSON(new RuntimeException());
        object.put("class", "xxx");
        Assert.assertEquals(Exception.class, JSON.parseObject(object.toJSONString(), Exception.class).getClass());
    }
View Full Code Here

import com.alibaba.fastjson.util.TypeUtils;

public class JSON_toJavaObject_test extends TestCase {

    public void test_0() throws Exception {
        A a = (A) JSON.toJavaObject(new JSONObject(), A.class);
        Assert.assertNotNull(a);
    }
View Full Code Here

        }

        String text = JSON.toJSONString(obj, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue);
        System.out.println(text);
        JSON.parseObject(text, clazz);
        JSONObject jsonObj = JSON.parseObject(text);
        Assert.assertEquals(jsonObj.getString("@type"), "com.alibaba.dubbo.demo.MyEsbResultModel2");
    }
View Full Code Here

        }

        String text = JSON.toJSONString(obj, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue);
        System.out.println(text);
        JSON.parseObject(text, clazz);
        JSONObject jsonObj = JSON.parseObject(text);
        Assert.assertEquals(jsonObj.getString("@type"), "org.mule.esb.model.tcc.result.EsbResultModel");
    }
View Full Code Here

        method.invoke(obj, "jobs");
       
        String text = JSON.toJSONString(obj, SerializerFeature.WriteClassName);
        System.out.println(text);
        JSON.parseObject(text, clazz);
        JSONObject jsonObj = JSON.parseObject(text);
        Assert.assertEquals(jsonObj.getString("@type"), "external.VO");
    }
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.