Working on JSON4Java

Posted by david, Tue Dec 25 19:10:00 UTC 2007

In addition to starting this blog, I just created a new project, JSON4Java. Its a fun little tinkering project that I started somewhat on accident.

I decided to use this as an opportunity to work more with a parser generator. I decided to use Ragel, since there is relatively little state needed to handle the JSON format. Ragel syntax had me stumped a few days – while writing the grammar was rather simple, embedding the actions can cause problems. In the end, I managed to tweak the thing until all of my test cases passed. Tests are absolutely vital for this sort of work!

I’m going to experiment now with adding a bit better error reporting, but also creating a somewhat SAX-ish interface on it to split out the generated parser from my business object for creating data. Ideally, the same interface could be used to both serialize and deserialize structures for JSON, and I’m hoping (if I get to that point) I can use Java annotations to allow mapping to more complex POJOs. I already split out the package into a json4java-core in anticipation for a json4java-pojo.

This sort of project also gives a level of freedom for experimentation and learning you just can’t get through typical commercial software development. I’ve finally got my unit testing ‘fu’ on, learning the new techniques in JUnit 4.4 (including assertThat); I’ve learned a bunch about maven; learned Ragel and implemented successfully a parser written in it. I’ve also started looking into newer Java features like Attributes, and around things like dependency injection and XML binding frameworks for ideas on allowing people to override functionality.

Filed Under: | Tags:

Comments