Package de.odysseus.staxon.json

Examples of de.odysseus.staxon.json.JsonXMLInputFactory


     * run a JSON to JSON XSLT transformationn XML string
     */
    @Override
    public Object transformMessage(MuleMessage message, String enc) throws TransformerException
    {
        XMLInputFactory inputFactory = new JsonXMLInputFactory();
        inputFactory.setProperty(JsonXMLInputFactory.PROP_MULTIPLE_PI, false);
        TransformerInputs inputs = new TransformerInputs(this, message.getPayload());
        Source source;
        try
        {
            if (inputs.getInputStream() != null)
            {
                source = new StAXSource(inputFactory.createXMLStreamReader(inputs.getInputStream(), enc == null ? "UTF-8" : enc));
            }
            else
            {
                source = new StAXSource(inputFactory.createXMLStreamReader(inputs.getReader()));
            }

            XMLOutputFactory outputFactory = new JsonXMLOutputFactory();
            outputFactory.setProperty(JsonXMLOutputFactory.PROP_AUTO_ARRAY, true);
            outputFactory.setProperty(JsonXMLOutputFactory.PROP_PRETTY_PRINT, true);
View Full Code Here


     * Use Staxon to convert JSON to an XML string
     */
    @Override
    protected Object doTransform(Object src, String enc) throws TransformerException
    {
        XMLInputFactory inputFactory = new JsonXMLInputFactory();
        inputFactory.setProperty(JsonXMLInputFactory.PROP_MULTIPLE_PI, false);
        TransformerInputs inputs = new TransformerInputs(this,src);
        Source source;
        try
        {
            if (inputs.getInputStream() != null)
            {
                source = new StAXSource(inputFactory.createXMLStreamReader(inputs.getInputStream(), enc == null ? "UTF-8" : enc));
            }
            else
            {
                source = new StAXSource(inputFactory.createXMLStreamReader(inputs.getReader()));
            }

            XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
            return convert(source, outputFactory);
        }
View Full Code Here

        // configure JSON to XML conversion property
        JsonXMLConfig config = new JsonXMLConfigBuilder().multiplePI(false).prettyPrint(false).build();
        //
        try {
            String charSetEncoding = (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
            XMLStreamReader reader = new JsonXMLInputFactory(config).createXMLStreamReader(inputStream, charSetEncoding);
            StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(reader);
            OMElement message = stAXOMBuilder.getDocumentElement();
            envelope.getBody().addChild(message);
        } catch (XMLStreamException e) {
            throw new AxisFault("Error while creating XMLStreamReader with JsonXMLInputFactory");
View Full Code Here

        namespaceMappings(namespaceMappings(config.namespaceMappings())).
        build();
  }
 
  protected JsonXMLInputFactory createInputFactory(Class<?> type, JsonXML config) throws JAXBException {
    return new JsonXMLInputFactory(toJsonXMLConfig(type, config));
  }
View Full Code Here

    Assert.assertFalse(new JsonXMLBinder().isBindable(getClass()));
  }
 
  @Test
  public void testCreateInputFactory() throws JAXBException {
    JsonXMLInputFactory factory = new JsonXMLBinder().createInputFactory(SampleRootElement.class, JsonXMLDefault.class.getAnnotation(JsonXML.class));
    Assert.assertEquals(Boolean.TRUE, factory.getProperty(JsonXMLInputFactory.PROP_MULTIPLE_PI));
    Assert.assertEquals(Character.valueOf(':'), factory.getProperty(JsonXMLInputFactory.PROP_NAMESPACE_SEPARATOR));
    Assert.assertNull(factory.getProperty(JsonXMLInputFactory.PROP_VIRTUAL_ROOT));

    factory = new JsonXMLBinder().createInputFactory(SampleRootElement.class, JsonXMLCustom.class.getAnnotation(JsonXML.class));
    Assert.assertEquals(Boolean.TRUE, factory.getProperty(JsonXMLInputFactory.PROP_MULTIPLE_PI));
    Assert.assertEquals(Character.valueOf('_'), factory.getProperty(JsonXMLInputFactory.PROP_NAMESPACE_SEPARATOR));
    Assert.assertEquals(new QName("sampleRootElement"), factory.getProperty(JsonXMLInputFactory.PROP_VIRTUAL_ROOT));
  }
View Full Code Here

public class DOMEventConsumerTest {
  @Test
  public void test1() throws XMLStreamException {
    StringReader json = new StringReader("{\"alice\":{\"@edgar\":\"david\",\"bob\":\"charlie\"}}");
    XMLEventReader reader = new JsonXMLInputFactory().createXMLEventReader(json);
    Document node = DOMEventConsumer.consume(reader);
   
    Node alice = node.getChildNodes().item(0);
    Assert.assertEquals("alice", alice.getLocalName());
    Assert.assertEquals("david", alice.getAttributes().getNamedItem("edgar").getNodeValue());
View Full Code Here

    } catch (ParserConfigurationException e) {
      throw new XMLStreamException(e);
    }

    StringReader json = new StringReader("{\"alice\":{\"@edgar\":\"david\",\"bob\":\"charlie\"}}");
    XMLEventReader reader = new JsonXMLInputFactory().createXMLEventReader(json);
    Document document = documentBuilder.newDocument();
    Node node = document.createElement("foo");
    document.appendChild(node);
    DOMEventConsumer.consume(reader, node);
   
View Full Code Here

  }
 
  @Test
  public void testXPath() throws XMLStreamException, XPathException {
    StringReader json = new StringReader("{\"alice\":{\"@edgar\":\"david\",\"bob\":\"charlie\"}}");
    XMLEventReader reader = new JsonXMLInputFactory().createXMLEventReader(json);
    Document document = DOMEventConsumer.consume(reader);
   
    XPath xpath = XPathFactory.newInstance().newXPath();
    Assert.assertEquals("charlie", xpath.evaluate("//alice[@edgar='david']/bob/text()", document));
  }
View Full Code Here

TOP

Related Classes of de.odysseus.staxon.json.JsonXMLInputFactory

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.