Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Jettison to go from JSON to DOM

Posted on 2009-05-11
9
Medium Priority
?
1,255 Views
Last Modified: 2013-11-08
The Jettison's User Guide provides an example on how to go from JSON to XML using the STaX API (http://jettison.codehaus.org/User%27s+Guide), but it doesn't say anything about the DOM API.

I read that Jettison 1.1 supports the DOM API. Does anyone have an example for this? I.e how to convert JSON to a W3C DOM object?

Alex
0
Comment
Question by:avernet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24361720
Even if they claim to have a DOM API it seems it is not really finished and even less documented. I have however found a reference to somebody who implemented a Dom parsing/serialzing feature. Maybe this helps you:
http://archive.jettison.codehaus.org/lists/dev@jettison.codehaus.org/msg/47DFE101.5030005@jboss.com
0
 
LVL 1

Author Comment

by:avernet
ID: 24368223
@Christofer,

Thank you for the link to this post. I had not tried BadgerFishDOMDocumentParser. Now I did, but get an NPE in Sun's XMLEventAllocatorImpl. I put more information on what I tried so far on the page below. You will see the code using BadgerFishDOMDocumentParser last on that page:

http://stackoverflow.com/questions/854344/using-jettison-to-go-from-json-to-dom-in-java

Alex
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24369002
Hi avernet,

I think the first approach sounds the most promissing one. You write that you are using Saxon and that Saxon doesn't impelment the STaX input. Well how about using Xalan instead?

With the following code you should be able to instantiate an instance, that you could use to create your identityTransformer (Which is nothing else than Input Source directly connected to the output source.

org.apache.xalan.xslt.XSLTProcessor processor =  org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor(  );
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:avernet
ID: 24370673
@ChristoferDutz,

Good idea. But at least with the version of Xalan we are using (2.5.1, and yes, I know there is a 2.7.1), I'm getting the following exception. Maybe support for StAXSource was added in a more recent version.

javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource
      orbeon.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:372)
      org.apache.jsp.gaga_jsp._jspService(gaga_jsp.java:82)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


0
 
LVL 1

Author Comment

by:avernet
ID: 24370697
I also added the code I test using the Xalan transformer, as well as the exception I am getting to:

http://stackoverflow.com/questions/854344/using-jettison-to-go-from-json-to-dom-in-java
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24372116
Mabe you should look at: http://woodstox.codehaus.org/ 
I have read, that some people use this to build Dom Objects from STaX
It seems to be compatible with jettison:
http://jettison.codehaus.org/dependencies.html
0
 
LVL 1

Author Comment

by:avernet
ID: 24388059
@ChristoferDutz,

I am not familiar with Woodstox. Are you saying that I can get a JAXP transformer implemented by Woodstox instead of using the one from Xalan (i.e. instead of org.apache.xalan.processor.TransformerFactoryImpl.newInstance().newTransformer())?
0
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 24421075
I haven't used Woodstox either. I just read that it's compatible with parsing STaX and generating from these events. So I just wanted to point you the driection without having been there myself ;-)
0
 
LVL 1

Author Comment

by:avernet
ID: 24424138
ChristoferDutz,

I got around this by sending XML from the browser to the server instead of JSON, so I lack the energy right not to try more things ;). But I think your last comment here will definitely steer people in the right direction. Thanks!

Alex
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question