Free for PREMIUM members
[Webinar] Streamline your web hosting managementRegister Today
JSON Three Ways
Jackson offers three alternative methods (one with two variants) for processing JSON:
Streaming API (aka "Incremental parsing/generation") reads and writes JSON content as discrete events.
org.codehaus.jackson.JsonParser reads, org.codehaus.jackson.JsonGenerator writes.
Inspired by the StAX API.
Tree Model provides a mutable in-memory tree representation of a JSON document.
org.codehaus.jackson.map.ObjectMapper can build trees; trees consist of JsonNode nodes.
The tree model is similar to the XML DOM.
Data Binding converts JSON to and from POJOs based either on property accessor conventions or annotations.
There are two variants: simple and full data binding
Simple data binding means converting to and from Java Maps, Lists, Strings, Numbers, Booleans and nulls
Full data binding means converting to and from any Java bean type (as well as "simple" types mentioned above)
org.codehaus.jackson.map.ObjectMapper performs the marshalling (writing JSON) and unmarshalling (reading JSON) for both variants.
Inspired by the annotation-based (code-first) variant of JAXB.
From usage perspective, one way to summarize these 3 methods is:
Streaming API is best performing (lowest overhead, fastest read/write; other 2 methods build on it)
Data Binding is often most convenient
Tree Model is most flexible
On the client-side, if you support only modern browsers, you can use the native JSON.stringify() API. Otherwise, the json2.js library is fine.
On the server-side, there are a herd of libraries to have a look at:
and many more Java JSON libraries...
I'm pointing you to Jackson first at it seems to be the fastest in many cases. However, I find its documentation harder to get my mind around every time I need to get back to it. Json-lib is sometimes easier to get to grasp with for smaller tasks that do not require top-speed, but with still completely acceptable results. Gson as also a good reputation and is very flexible, however the previous benchmarks I came across seemed to indicate that it did not perform as well as Jackson. The newly released 1.5 version might have improved that, but I don't know.
It comes down to the degree of flexibility you want, the performance you need, and whether you want a simple API or if you don't mind a more complex one.
With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $79.20.
Premium members get this course for $159.20.
Premium members get this course for $168.80.
Premium members get this course for $39.20.
Premium members get this course for $151.20.
Premium members get this course for $349.00.
Premium members get this course for $12.00.