Jackson Vs. Gson

JavaJsonComparisonGsonJackson

Java Problem Overview


After searching through some existing libraries for JSON, I have finally ended up with these two:

  • Jackson
  • Google GSon

I am a bit partial towards GSON, but word on the net is that GSon suffers from a certain celestial performance issue (as of Sept 2009).

I am continuing my comparison; in the meantime, I'm looking for help to make up my mind.

Java Solutions


Solution 1 - Java

I did this research the last week and I ended up with the same 2 libraries. As I'm using Spring 3 (that adopts Jackson in its default Json view 'JacksonJsonView') it was more natural for me to do the same. The 2 lib are pretty much the same... at the end they simply map to a json file! :)

Anyway as you said Jackson has a + in performance and that's very important for me. The project is also quite active as you can see from their web page and that's a very good sign as well.

Solution 2 - Java

Jackson and Gson are the most complete Java JSON packages regarding actual data binding support; many other packages only provide primitive Map/List (or equivalent tree model) binding. Both have complete support for generic types, as well, as enough configurability for many common use cases.

Since I am more familiar with Jackson, here are some aspects where I think Jackson has more complete support than Gson (apologies if I miss a Gson feature):

  • Extensive annotation support; including full inheritance, and advanced "mix-in" annotations (associate annotations with a class for cases where you can not directly add them)
  • Streaming (incremental) reading, writing, for ultra-high performance (or memory-limited) use cases; can mix with data binding (bind sub-trees) -- EDIT: latest versions of Gson also include streaming reader
  • Tree model (DOM-like access); can convert between various models (tree <-> java object <-> stream)
  • Can use any constructors (or static factory methods), not just default constructor
  • Field and getter/setter access (earlier gson versions only used fields, this may have changed)
  • Out-of-box JAX-RS support
  • Interoperability: can also use JAXB annotations, has support/work-arounds for common packages (joda, ibatis, cglib), JVM languages (groovy, clojure, scala)
  • Ability to force static (declared) type handling for output
  • Support for deserializing polymorphic types (Jackson 1.5) -- can serialize AND deserialize things like List correctly (with additional type information)
  • Integrated support for binary content (base64 to/from JSON Strings)

Solution 3 - Java

Gson 1.6 now includes a low-level streaming API and a new parser which is actually faster than Jackson.

Solution 4 - Java

Adding to other answers already given above. If case insensivity is of any importance to you, then use Jackson. Gson does not support case insensitivity for key names, while jackson does.

Here are two related links

(No) Case sensitivity support in Gson : https://stackoverflow.com/questions/6332651/gson-how-to-get-a-case-insensitive-element-from-json

Case sensitivity support in Jackson https://gist.github.com/electrum/1260489

Solution 5 - Java

It seems that GSon don't support JAXB. By using JAXB annotated class to create or process the JSON message, I can share the same class to create the Restful Web Service interface by using spring MVC.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSuraj ChandranView Question on Stackoverflow
Solution 1 - JavamickthompsonView Answer on Stackoverflow
Solution 2 - JavaStaxManView Answer on Stackoverflow
Solution 3 - JavainderView Answer on Stackoverflow
Solution 4 - JavasnegiView Answer on Stackoverflow
Solution 5 - Javaraymond.mh.ngView Answer on Stackoverflow