views:

1782

answers:

2
+9  Q: 

Jackson Vs. Gson

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 certain celestial performance issue.

I am continuing my comparison, in the meanwhile I was looking for help to make up my mind.

+4  A: 

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.

al nik
Also, Google GSon does not yet suppor circular references. Does Jackson handle them ?
Guido
Circular References support... that should be a primary feature but I'm not sure if it does support them, I've never encountered a circular reference so far (even if they should be quite common I think, especially in the model). Here's another benchmark that can highlight how fast Jackson is if compared to GSon. It looks 100x faster in Serialization/Deserialization http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking
al nik
Jackson does not handle circular references currently. If that is important, XStream does; not sure if any native json package does (flex-json perhaps?)
StaxMan
+2  A: 

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)
  • 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)
StaxMan