Examples of AbstractXMLStreamWriter


Examples of org.codehaus.jettison.AbstractXMLStreamWriter

    // issue 64
    public void testPrimitiveInfinityNaN() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);

        w.writeStartDocument();
        w.writeStartElement("root");


        w.writeStartElement("subchild1");
        w.writeCharacters("Infinity");
        w.writeEndElement();

        w.writeStartElement("subchild1");
        w.writeCharacters("NaN");
        w.writeEndElement();


        w.writeEndElement();
        w.writeEndDocument();

        w.close();
        strWriter.close();
        String expected = "{\"root\":{\"subchild1\":[\"Infinity\",\"NaN\"]}}";
        String actual = strWriter.toString();
        assertEquals(expected, actual);
    }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

    //issue 29
    public void testComplexElements() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("", "a", "");

        w.writeStartElement("", "o", "");
        w.writeAttribute("class", "string");
        w.writeCharacters("1");
        w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"a\":{\"o\":{\"@class\":\"string\",\"$\":\"1\"}}}", strWriter.toString());
    }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

    }   
   
    public void testSingleArrayElement() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
    w.serializeAsArray(con.createKey("", "", "array-a"));

    w.writeStartDocument();
    w.writeStartElement("", "array-a", "");

    w.writeStartElement("", "a", "");
    w.writeStartElement("", "n", "");
    w.writeCharacters("1");
    w.writeEndElement();
    w.writeEndElement();

    w.writeEndElement();
    w.writeEndDocument();

    w.close();
    strWriter.close();

    assertEquals("{\"array-a\":[{\"a\":{\"n\":1}}]}", strWriter.toString());
  }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

  }
   
    public void testEmptySerializedArrayElement() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
        w.serializeAsArray(con.createKey("", "", "array-a"));

        w.writeStartDocument();
        w.writeStartElement("", "array-a", "");

        w.writeEndElement();
        w.writeEndDocument();

        w.close();
        strWriter.close();

        assertEquals("{\"array-a\":[\"\"]}", strWriter.toString());
    }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

    }
   
    public void testNestedSerializedArrayElement() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
        w.serializeAsArray(con.createKey("", "", "docs"));
        w.serializeAsArray(con.createKey("", "", "filters"));
        w.serializeAsArray(con.createKey("", "", "hosts"));

        w.writeStartDocument();
        w.writeStartElement("", "docs", "");
        w.writeStartElement("", "doc", "");
       
        w.writeStartElement("", "id", "");
        w.writeCharacters("24");
        w.writeEndElement();
       
        w.writeStartElement("", "filters", "");
        w.writeEndElement();
       
        w.writeStartElement("", "hosts", "");
        w.writeStartElement("", "host", "");
        w.writeStartElement("", "name", "");
        w.writeCharacters("foobar.com");
        w.writeEndElement(); //name
        w.writeStartElement("", "ip", "");
        w.writeCharacters("255.255.255.255");
        w.writeEndElement(); //ip
        w.writeEndElement(); // host
        w.writeEndElement(); //hosts

        w.writeEndElement(); // doc
        w.writeEndElement(); // docs
        w.writeEndDocument();

        w.close();
        strWriter.close();

        assertEquals("{\"docs\":[{\"doc\":{\"id\":24,\"filters\":[\"\"],\"hosts\":[{\"host\":{\"name\":\"foobar.com\",\"ip\":\"255.255.255.255\"}}]}}]}", strWriter.toString());
    }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

    }
   
    public void testSingleArrayElementIgnore() throws Exception {
    StringWriter strWriter = new StringWriter();
    MappedNamespaceConvention con = new MappedNamespaceConvention();
    AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);

    w.writeStartDocument();
    w.writeStartElement("", "array-a", "");

    w.writeStartElement("", "a", "");
    w.writeStartElement("", "n", "");
    w.writeCharacters("1");
    w.writeEndElement();
    w.writeEndElement();

    w.writeEndElement();
    w.writeEndDocument();

    w.close();
    strWriter.close();

    assertEquals("{\"array-a\":{\"a\":{\"n\":1}}}", strWriter.toString());
  }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

   
    //issue 26
    public void testArraysAndAttributes() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("root");
       
        w.writeStartElement("child");
        w.writeAttribute("x", "y");
        w.writeCharacters("value");
        w.writeEndElement();
       
        w.writeStartElement("child");
        w.writeAttribute("a", "b");
        w.writeCharacters("value");
        w.writeEndElement();
       
        w.writeStartElement("child");
        w.writeAttribute("x", "z");
        w.writeCharacters("value");
        w.writeEndElement();       
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"root\":{\"child\":[{\"@x\":\"y\",\"$\":\"value\"},{\"@a\":\"b\",\"$\":\"value\"},{\"@x\":\"z\",\"$\":\"value\"}]}}", strWriter.toString());
    }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

    public void testConverter() throws Exception {
        StringWriter strWriter = new StringWriter();
        Configuration config = new Configuration();
        config.setTypeConverter(new SimpleConverter());
        MappedNamespaceConvention con = new MappedNamespaceConvention(config);
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);

        w.writeStartDocument();
        w.writeStartElement("root");
        w.writeCharacters("true");
        w.writeEndElement();

        w.writeEndDocument();

        w.close();
        strWriter.close();

        assertEquals("{\"root\":\"true\"}", strWriter.toString());       
    }
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

        Map xtoj = new HashMap();
        xtoj.put("http://foo/", "foo");
        Configuration conf = new Configuration(xtoj);
        conf.setAttributeKey("!");
        MappedNamespaceConvention con = new MappedNamespaceConvention(conf);
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("root");
        w.writeAttribute("att", "attvalue");
        w.writeAttribute("http://foo/", "att2", "attvalue");
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"root\":{\"!att\":\"attvalue\",\"!foo.att2\":\"attvalue\"}}", strWriter.toString());
    }  
View Full Code Here

Examples of org.codehaus.jettison.AbstractXMLStreamWriter

   
    // issue 63
    public void testArrayAsFirstInAnArray() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
        w.serializeAsArray(con.createKey("", "", "bazs"));
        w.serializeAsArray(con.createKey("", "", "quacks"));

        w.writeStartDocument();
        w.writeStartElement("Foo");
          w.writeStartElement("bazs"); // array
            w.writeStartElement("quacks"); // array
              w.writeStartElement("goof");
              w.writeEndElement();
            w.writeEndElement();
        w.writeEndElement();
        w.writeEndElement();
        w.writeEndDocument();

        w.close();
        strWriter.close();

        assertEquals("{\"Foo\":{\"bazs\":[{\"quacks\":[{\"goof\":\"\"}]}]}}", strWriter.toString());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.