Flexjson: A DSL approach to JSON for Java

Written by on April 20th, 2007 in Ajax News.

Charlie Hubbard has released Flexjson, a lightweight JSON library for Java. Most JSON serializers mimic object serialization libraries and try to serialize the entire object graph from the object being turned into JSON. This causes problems when you want a connected object model on your server, but you can’t send that object model to the client because the serialization library will try to send the entire object graph. This is terrible for performance, causes most JSON libraries to blow up if they encounter circular references, makes it difficult to follow good OO practices, and makes it nearly impossible to use libraries such as Hibernate. Other JSON libraries require you to create a lot of boiler plate code to translate your object representation into a JSON object.

Flexjson tries to solve both of these problems by using a DSL approach to sending JSON. You don’t have to create lots of boiler plate code or modify your object model to make it work.

Examples:

JAVASCRIPT:

  1.  
  2. return new JSONSerializer().include(”hobbies”, “favoriteMovies”).serialize(person);
  3.  
  4. return new JSONSerializer().exclude(”password”).include(”hobbies”).serialize(person);
  5.  

Source: Ajaxian
Original Article: http://ajaxian.com/archives/flexjson-a-dsl-approach-to-json-for-java

Leave a Reply

You must be logged in to post a comment.



Site Navigation