Package org.codehaus.jettison.badgerfish

Examples of org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter


    public static XMLStreamWriter createWriter(final Writer writer,
                                               final JettisonConfig config) throws IOException {
        switch (config.getNotation()) {
            case BADGERFISH:
                return new BadgerFishXMLStreamWriter(writer);
            case MAPPED_JETTISON:
                Configuration jmConfig;
                if (null == config.getXml2JsonNs()) {
                    jmConfig = new Configuration();
                } else {
View Full Code Here


                    return new Stax2JacksonWriter(bodyGenerator, config);
                    }
            case MAPPED:
                return JsonXmlStreamWriter.createWriter(writer, config);
            case BADGERFISH:
                return new BadgerFishXMLStreamWriter(writer);
            case MAPPED_JETTISON:
                Configuration jmConfig;
                if (null == config.getXml2JsonNs()) {
                    jmConfig = new Configuration();
                } else {
View Full Code Here

                    return new Stax2JacksonWriter(JacksonRootStrippingGenerator.createRootStrippingGenerator(new JsonFactory().createJsonGenerator(writer)));
                }
            case MAPPED:
                return JsonXmlStreamWriter.createWriter(writer, config.isRootUnwrapping(), config.getArrays(), config.getNonStrings(), config.getAttributeAsElements());
            case BADGERFISH:
                return new BadgerFishXMLStreamWriter(writer);
            case MAPPED_JETTISON:
                Configuration jmConfig;
                if (null == config.getXml2JsonNs()) {
                    jmConfig = new Configuration();
                } else {
View Full Code Here

   }

   public void marshal(Object o, Writer writer)
           throws JAXBException
   {
      BadgerFishXMLStreamWriter badger = new BadgerFishXMLStreamWriter(writer);
      marshaller.marshal(o, badger);
   }
View Full Code Here

    }
   
    //returns the writer for the badgerfish format
    @Override
    protected XMLStreamWriter getJSONWriter(Writer writer, MessageContext messageContext) {
        return new BadgerFishXMLStreamWriter(writer);
    }
View Full Code Here

import org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter;

public class BadgerFishXMLStreamWriterTest extends TestCase {
    public void testRootWithText() throws Exception {
        StringWriter strWriter = new StringWriter();
        AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("alice");
        w.writeCharacters("bob");
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertJSONEquals("{\"alice\":{\"$\":\"bob\"}}", strWriter.toString());
    }
View Full Code Here

        assertEquals(string, string2);
    }

    public void testTwoChildren() throws Exception {
        StringWriter strWriter = new StringWriter();
        AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("alice");

        w.writeStartElement("bob");
        w.writeCharacters("charlie");
        w.writeEndElement();
       
        w.writeStartElement("david");
        w.writeCharacters("edgar");
        w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertJSONEquals("{\"alice\":{\"bob\":{\"$\":\"charlie\"},"+
                         "\"david\":{\"$\":\"edgar\"}}}", strWriter.toString());
    }
View Full Code Here

                         "\"david\":{\"$\":\"edgar\"}}}", strWriter.toString());
    }
   
    public void testTwoChildrenWithSameName() throws Exception {
        StringWriter strWriter = new StringWriter();
        AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("alice");

        w.writeStartElement("bob");
        w.writeCharacters("charlie");
        w.writeEndElement();
       
        w.writeStartElement("bob");
        w.writeCharacters("david");
        w.writeEndElement();
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertJSONEquals("{\"alice\":{\"bob\":[{\"$\":\"charlie\"},{\"$\":\"david\"}]}}",
                         strWriter.toString());
    }
View Full Code Here

                         strWriter.toString());
    }

    public void testMultipleChildrenAgain() throws Exception {
        StringWriter strWriter = new StringWriter();
        AbstractXMLStreamWriter xsw = new BadgerFishXMLStreamWriter(strWriter);
       
        xsw.writeStartDocument();
        xsw.writeStartElement("Ratings");

        xsw.writeStartElement("Rating");
        xsw.writeAttribute("id", "100");
        xsw.writeAttribute("value", "3");
        xsw.writeEndElement();

        xsw.writeStartElement("Rating");
        xsw.writeAttribute("id", "200");
        xsw.writeAttribute("value", "4");
        xsw.writeEndElement();

        xsw.writeStartElement("Rating");
        xsw.writeAttribute("id", "300");
        xsw.writeAttribute("value", "5");
        xsw.writeEndElement();

        xsw.writeEndElement();
        xsw.writeEndDocument ();
        xsw.flush();

        xsw.close();
        strWriter.close();
        System.out.println(strWriter.toString());
       
        assertJSONEquals("{\"Ratings\":{\"Rating\":[" +
                        "{\"@id\":\"100\",\"@value\":\"3\"}," +
View Full Code Here

                         strWriter.toString());
    }
   
    public void testAttributeAndText() throws Exception {
        StringWriter strWriter = new StringWriter();
        AbstractXMLStreamWriter w = new BadgerFishXMLStreamWriter(strWriter);
       
        w.writeStartDocument();
        w.writeStartElement("alice");
       
        w.writeAttribute("charlie", "david");
        w.writeCharacters("bob");
       
        w.writeEndElement();
        w.writeEndDocument();
       
        w.close();
        strWriter.close();
       
        assertJSONEquals("{\"alice\":{\"@charlie\":\"david\",\"$\":\"bob\"}}",
                         strWriter.toString());
    }
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter

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.