Wednesday, November 15th, 2006

Jettison: JSON StAX Parser

Category: Java, Library

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

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

Posted by Dion Almaer at 7:27 am
Comment here

+++--
3.1 rating from 23 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.