Package org.codehaus.jettison

Examples of org.codehaus.jettison.AbstractXMLStreamWriter


        StringWriter strWriter = new StringWriter();
       
        Map xtoj = new HashMap();
        xtoj.put("http://foo/", "foo");
        MappedNamespaceConvention con = new MappedNamespaceConvention(new Configuration(xtoj));
        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


        atts.add(new QName("http://foo/", "att2"));
       
        Configuration c = new Configuration(xtoj, atts, null);
       
        MappedNamespaceConvention con = new MappedNamespaceConvention(c);
        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

       
        Configuration c = new Configuration(xtoj, atts, null);
        c.setSupressAtAttributes(true);
       
        MappedNamespaceConvention con = new MappedNamespaceConvention(c);
        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

    }
   
    public void testTwoChildren() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("root");
       
        w.writeStartElement("child1");
        w.writeEndElement();
       
        w.writeStartElement("child2");
        w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"root\":{\"child1\":\"\",\"child2\":\"\"}}", strWriter.toString());
    }
View Full Code Here

    }
   
    public void testTwoChildrenWithSubChild() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("root");
       
        w.writeStartElement("child1");
        w.writeStartElement("subchild");
        w.writeEndElement();
        w.writeEndElement();
       
        w.writeStartElement("child2");
        w.writeStartElement("subchild");
        w.writeEndElement();
        w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"root\":{" +
                        "\"child1\":{\"subchild\":\"\"}," +
                        "\"child2\":{\"subchild\":\"\"}}}", strWriter.toString());
View Full Code Here

    }
    public void testTwoChildrenWithSubChildWithText() throws Exception {
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("root");
       
        w.writeStartElement("child1");
        w.writeStartElement("subchild1");
        w.writeCharacters("test");
        w.writeEndElement();
       
        w.writeStartElement("subchild2");
        w.writeCharacters("test");
        w.writeEndElement();
       
        w.writeEndElement();
       
        w.writeStartElement("child2");
        w.writeStartElement("subchild");
        w.writeCharacters("test");
        w.writeEndElement();
        w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"root\":{" +
                        "\"child1\":{\"subchild1\":\"test\",\"subchild2\":\"test\"}," +
                        "\"child2\":{\"subchild\":\"test\"}}}", strWriter.toString());
View Full Code Here

    }
   
    public void testNestedArrayOfChildren() 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.writeStartElement("subchild2");
              w.writeCharacters("first sub2");
            w.writeEndElement();
       
            w.writeStartElement("subchild2");
              w.writeStartElement("subchild3");
                w.writeCharacters("first sub3");
              w.writeEndElement();
              w.writeStartElement("subchild3");
                w.writeCharacters("second sub3");
              w.writeEndElement();
            w.writeEndElement();
       
            w.writeStartElement("subchild2");
              w.writeCharacters("third sub2");
            w.writeEndElement();
       
          w.writeEndElement();
       
          w.writeStartElement("subchild1");
            w.writeCharacters("sub1");
          w.writeEndElement();
         
          //w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"root\":{\"subchild1\":[{\"subchild2\":[\"first sub2\",{\"subchild3\":[\"first sub3\",\"second sub3\"]},\"third sub2\"]},\"sub1\"]}}"
, strWriter.toString());
    }
View Full Code Here

   
    //ISSUE-48
    public void testNestedArrayOfChildrenWithComplexElements() 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.writeStartElement("subchild2");
              w.writeCharacters("first sub2");
            w.writeEndElement();
           
          w.writeEndElement();
         
          w.writeStartElement("subchild1");
          w.writeCharacters("text");
        w.writeEndElement();
       
          w.writeStartElement("subchild1");
          w.writeCharacters("text1");
        w.writeEndElement();
     
      w.writeStartElement("outer");
        w.writeCharacters("test");
      w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals(strWriter.toString(), "{\"root\":{\"subchild1\":[{\"subchild2\":\"first sub2\"},\"text\",\"text1\"],\"outer\":\"test\"}}");
    }
View Full Code Here

    }
   
    public void testArrayOfChildren() 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.writeCharacters("first");
        w.writeEndElement();
       
        w.writeStartElement("child");
        w.writeCharacters("second");
        w.writeEndElement();
       
        w.writeStartElement("child");
        w.writeCharacters("third");
        w.writeEndElement();
       
        w.writeEndElement();
       
        w.writeStartElement("other");
        w.writeCharacters("test");
        w.writeEndElement();
       
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertEquals("{\"root\":{\"child\":[\"first\",\"second\",\"third\"]},\"other\":\"test\"}", strWriter.toString());
    }
View Full Code Here

    public void testBootstrapConverter() throws Exception {
        System.setProperty( "jettison.mapped.typeconverter.class", ReplacementTypeConverter.class.getName() );
        StringWriter strWriter = new StringWriter();
        MappedNamespaceConvention con = new MappedNamespaceConvention();
        AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
        w.writeStartDocument();
        w.writeStartElement("root");

        w.writeStartElement("subchild1");
        w.writeCharacters("Not success");
        w.writeEndElement();

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

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

TOP

Related Classes of org.codehaus.jettison.AbstractXMLStreamWriter

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.