Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONStringer


    /**
     * Test the contructor.
     */
    public void test_new() {
        JSONStringer jStringer = new JSONStringer();
    }
View Full Code Here


     * Test the String empty object contructor.
     */
    public void test_WriteEmptyObject() {
        Exception ex = null;
        try{
            JSONStringer jStringer = new JSONStringer();
            jStringer.object();
            jStringer.endObject();
            String str = jStringer.toString();
            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{}"));
        }catch(Exception ex1){
            ex = ex1;
View Full Code Here

     * Test the String empty object contructor.
     */
    public void test_WriteEmptyObjectClose() {
        Exception ex = null;
        try{
            JSONStringer jStringer = new JSONStringer();
            jStringer.object();
            jStringer.close();
            String str = jStringer.toString();
            System.out.println("STRING: " + str);
            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{}"));
        }catch(Exception ex1){
View Full Code Here

     * Test the String empty object contructor.
     */
    public void test_WriteEmptyArray() {
        Exception ex = null;
        try{
            JSONStringer jStringer = new JSONStringer();
            jStringer.array();
            jStringer.endArray();
            String str = jStringer.toString();
            // Verify it parses.
            JSONArray test = new JSONArray(str);
            assertTrue(str.equals("[]"));
        }catch(Exception ex1){
            ex = ex1;
View Full Code Here

     * Test a simple object with multiple keys of varying types
     */
    public void test_WriteObjectComplex() {
        Exception ex = null;
        try{
            JSONStringer jStringer = new JSONStringer();
            jStringer.object();
            jStringer.key("string");
            jStringer.value("String1");
            jStringer.key("bool");
            jStringer.value(false);
            jStringer.key("number");
            jStringer.value(1);

            // Place an object
            jStringer.key("object");
            jStringer.object();
            jStringer.key("string");
            jStringer.value("String2");
            jStringer.endObject();

            // Place an array
            jStringer.key("array");
            jStringer.array();
            jStringer.value(1);
            jStringer.value((double)2);
            jStringer.value((short)3);
            jStringer.endArray();

            //Close top object.
            jStringer.endObject();

            String str = jStringer.toString();

            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{\"string\":\"String1\",\"bool\":false,\"number\":1,\"object\":{\"string\":\"String2\"},\"array\":[1,2.0,3]}"));
        }catch(Exception ex1){
View Full Code Here

     * Test a simple object with multiple keys of varying types
     */
    public void test_WriteArrayComplex() {
        Exception ex = null;
        try{
            JSONStringer jStringer = new JSONStringer();
            jStringer.array();
            jStringer.value("String1");
            jStringer.value(false);
            jStringer.value(1);

            // Place an object
            jStringer.object();
            jStringer.key("string");
            jStringer.value("String2");
            jStringer.endObject();

            // Place an array
            jStringer.array();
            jStringer.value(1);
            jStringer.value((double)2);
            jStringer.value((short)3);
            jStringer.endArray();

            //Close top array.
            jStringer.endArray();

            String str = jStringer.toString();

            // Verify it parses.
            JSONArray test = new JSONArray(str);
            assertTrue(str.equals("[\"String1\",false,1,{\"string\":\"String2\"},[1,2.0,3]]"));
        }catch(Exception ex1){
View Full Code Here

     * Test that trying operations after the stringer was returned that they fail.
     */
    public void test_OptsAfterCloseFail() {
        Exception ex = null;
        try{
            JSONStringer jStringer = new JSONStringer();
            jStringer.array();
            jStringer.toString();

            // This should die.
            jStringer.endArray();
        }catch(Exception ex1){
            ex = ex1;
        }
        assertTrue(ex instanceof IllegalStateException);
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.json4j.JSONStringer

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.