I needed some way to convert diagram specifications to/from plain text in the CSUF database modeler; for simplicity, I settled on the
JSON format. Yes, while I am aware that JSON cannot handle circular references (but I do have a solution), it is much easier to parse/generate than XML and neatly avoids the difficulty of defining an obscure binary.
I chose not to use an existing library for a couple of reasons:
- Apparently, most Java libraries employ a DOM-like approach to serialize/deserialize Java objects. A full DOM tree is convenient, but for my purposes it would unnecessarily duplicate objects.
- One learns more by doing, and, in any case, I crave the amusement.
Thus, after a week of work, I introduce
JASon (
JSON
API
Simplified), a barebones stream parser/generator library that takes design cues from the
SAX approach: it parses JSON in a single pass using callback methods for client interaction. This method is particularly memory-efficient since the entire document is never held in memory at once - advantageous when dealing with potentially complex diagram specifications. It also includes a complimentary generator.
Some features:
- Compliant with RFC 4627
- Validates input/output for well-formedness
- Parser/generator objects "recycle" themselves to minimize unnecessary object creation.
- If a DOM tree is desired, there is a DOM utility class that adapts the stream parser to produce one.
The
project is hosted at Launchpad, where the source code and JAR builds for the 0.1.0 release are available at the
trunk and
downloads, respectively.
To get a local copy of the latest source code, run
bzr branch lp:libjason (you need
Bazaar for this).
For the Javadoc, run
bzr branch lp:libjason/javadoc (viewing raw files is currently not possible at Launchpad).
Post a Comment