Jettison
  1. Jettison
  2. JETTISON-101

getVersion of the class org.codehaus.jettison.AbstractXMLStreamReader could return 1.0 or 1.1 to enable to create DOM document with Xalan

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: 1.3.6
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The following code

      JSONObject object = new JSONObject("{'firstName':{'altitude':'39000','pilot':{'firstName':'Buzz','lastName':'Aldrin'},'mission':'apollo 11'}}");
      AbstractXMLStreamReader reader = new BadgerFishXMLStreamReader(object);
      Source source = new StAXSource(reader);		
      DOMResult result = new DOMResult();
      TransformerFactory transFactory = TransformerFactory.newInstance();
      Transformer transformer = transFactory.newTransformer();
      transformer.transform(source, result);
      

      throw an exception:

      Exception in thread "main" javax.xml.transform.TransformerException: java.lang.NullPointerException
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:716)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
      at org.ow2.petals.binding.rest.json.test.JSONTest.toXML(JSONTest.java:155)
      at org.ow2.petals.binding.rest.json.test.JSONTest.main(JSONTest.java:89)
      Caused by: java.lang.NullPointerException
      at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.setXmlVersion(CoreDocumentImpl.java:856)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.setDocumentInfo(SAX2DOM.java:150)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.startElement(SAX2DOM.java:160)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(ToXMLSAXHandler.java:204)
      at com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(ToSAXHandler.java:277)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.startElement(ToXMLSAXHandler.java:646)
      at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.handleStartElement(StAXStream2SAX.java:338)
      at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.bridge(StAXStream2SAX.java:164)
      at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.parse(StAXStream2SAX.java:120)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:656)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707)
      ... 3 more
      ---------
      java.lang.NullPointerException
      at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.setXmlVersion(CoreDocumentImpl.java:856)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.setDocumentInfo(SAX2DOM.java:150)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.startElement(SAX2DOM.java:160)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(ToXMLSAXHandler.java:204)
      at com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(ToSAXHandler.java:277)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.startElement(ToXMLSAXHandler.java:646)
      at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.handleStartElement(StAXStream2SAX.java:338)
      at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.bridge(StAXStream2SAX.java:164)
      at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.parse(StAXStream2SAX.java:120)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:656)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
      at org.ow2.petals.binding.rest.json.test.JSONTest.toXML(JSONTest.java:155)
      at org.ow2.petals.binding.rest.json.test.JSONTest.main(JSONTest.java:89)

      If the method getVersion of the class org.codehaus.jettison.AbstractXMLStreamReader is redefined in this way

      AbstractXMLStreamReader reader = new BadgerFishXMLStreamReader(object) {
      	@Override
      	public String getVersion() {
      	   return "1.0";
      	}
      };
      

      it works.

      I think it could be a nice improvement to allow parsing JSON to create a DOM document from it (I am conscious that DOM is rather for XML document).

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Sergey Beryozkin
            Reporter:
            Nicolas Oddoux
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: