Activate your free membership today | Log-in

Wednesday, November 15th, 2006

Jettison: JSON StAX Parser

Category: Java, Library

<p>If you live in the world of Java, a new JSON parser has been born called Jettison:

Jettison is a collection of StAX (streaming XML) parsers and writers which read and write JSON. This allows nearly transparent enablement of JSON based web services in services frameworks like CXF.

There are currently two included conventions for mapping JSON to XML. The first, is BadgerFish which implements the full XML infoset in JSON using various techniques. The second, is called the "mapped" convention. It allows you to manually map XML namespaces to JSON element prefixes.

Using the mapped StAX implementation

JAVA:
  1.  
  2. import org.codehaus.jettison.mapped.MappedXMLInputFactory;
  3. import org.codehaus.jettison.mapped.MappedXMLOutputFactory;
  4.  
  5. HashMap<string , String> nstojns = new HashMap</string><string ,String>();
  6. nstojns.put("http://acme.com", "acme");
  7.  
  8. MappedXMLInputFactory xif = new MappedXMLInputFactory(nstojns);
  9. xif.createXMLStreamReader(...);
  10.  
  11. MappedXMLOutputFactory xof = new MappedXMLOutputFactory(nstojns);
  12. xof.createXMLStreamWriter(...);
  13.  

Related Content:

  • Alternatives to JAXP
    This follow-up tip discusses two popular alternatives to JAXP and why some Java programmers prefer...
  • Introducing Axiom
    An XML Object model should be memory efficient and fast in processing XML. These two goals are very difficult to satisfy with the technologies that...
  • The Axis2 Web services toolkit
    Apache's Axis2 Web services toolkit has built itself on the new AXIOM object model and StAX parsing. This tip looks into its evolution and what it...
  • The elements of Web service performance
    Ever since the beginning of Web services as a class of application, performance, in terms of response time and memory requirements, has been a major...
  • WSDL parsers
    Anne Thomas Manes discusses how to go about generating XML files that can be used to integrate two different...

Posted by Dion Almaer at 7:27 am
Comment here

+++--
3.1 rating from 18 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.