Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONWriter


     */
    public void test_WriteObjectAttrBoolean() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.key("foo");
            jWriter.value(true);
            jWriter.close();
            String str = w.toString();
            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{\"foo\":true}"));
        }catch(Exception ex1){
View Full Code Here


     */
    public void test_WriteObjectAttrObject() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.key("foo");
            jWriter.object();
            jWriter.key("foo");
            jWriter.value(true);
            jWriter.endObject();
            jWriter.endObject();
            jWriter.close();
            String str = w.toString();
           
            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{\"foo\":{\"foo\":true}}"));
View Full Code Here

     */
    public void test_WriteObjectAttrArray() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.key("foo");
            jWriter.array();
            jWriter.value(true);
            jWriter.endArray();
            jWriter.endObject();
            jWriter.close();
            String str = w.toString();
           
            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{\"foo\":[true]}"));
View Full Code Here

     */
    public void test_WriteObjectAttrJSONObject() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.key("foo");

            // Verify we can put a JSONObject into the stream!
            JSONObject jObj = new JSONObject();
            jObj.put("foo", true);
            jWriter.value(jObj);

            jWriter.endObject();
            jWriter.close();

            String str = w.toString();
            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{\"foo\":{\"foo\":true}}"));
View Full Code Here

     */
    public void test_WriteObjectAttrJSONArray() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.key("foo");

            // Verify we can put a JSONObject into the stream!
            JSONArray jArray = new JSONArray();
            jArray.put(true);
            jWriter.value(jArray);

            jWriter.endObject();
            jWriter.close();

            String str = w.toString();
            // Verify it parses.
            JSONObject test = new JSONObject(str);
            assertTrue(str.equals("{\"foo\":[true]}"));
View Full Code Here

     */
    public void test_WriteObjectComplex() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.key("string");
            jWriter.value("String1");
            jWriter.key("bool");
            jWriter.value(false);
            jWriter.key("number");
            jWriter.value(1);

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

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

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

            jWriter.close();

            String str = w.toString();

            // Verify it parses.
            JSONObject test = new JSONObject(str);
View Full Code Here

     */
    public void test_WriteArrayComplex() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.array();
            jWriter.value("String1");
            jWriter.value(false);
            jWriter.value(1);

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

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

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

            jWriter.close();
            String str = w.toString();

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

     */
    public void test_ObjectNoKeyValueFail() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.value(true);
            jWriter.endObject();
        }catch(Exception ex1){
            ex = ex1;
        }
        assertTrue(ex instanceof IllegalStateException);
    }
View Full Code Here

     */
    public void test_ObjectKeyValueNoKeyValueFail() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
            jWriter.object();
            jWriter.key("foo");
            jWriter.value(true);
           
            // This should die with IllegalStateException...
            jWriter.value(false);
            jWriter.endObject();
        }catch(Exception ex1){
            ex = ex1;
        }
        assertTrue(ex instanceof IllegalStateException);
    }
View Full Code Here

     */
    public void test_NoObjectKeyFail() {
        Exception ex = null;
        try{
            StringWriter w = new StringWriter();
            JSONWriter jWriter = new JSONWriter(w);
           
            // This should die.
            jWriter.key("foo");
        }catch(Exception ex1){
            ex = ex1;
        }
        assertTrue(ex instanceof IllegalStateException);
    }
View Full Code Here

TOP

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

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.