views:

800

answers:

2

I'm making pretty heavy use of JSON parsing in an app I'm writing. Most of what I have done is already implemented using Android's built in JSONObject library (is it json-lib?).

JSONObject appears to create instances of absolutely everything in the JSON string... even if I don't end up using all of them.

My app currently runs pretty well, even on a G1.

My question is this: are the speed and memory benefits from using a stream parser like Jackson worth all the trouble?

By trouble, I mean this: As far as I can tell, there are three downsides to using Jackson instead of the built in library:

  1. Dependency on an external library. This makes your .apk bigger in the end. Not a huge deal.
  2. Your app is more fragile. Since the parsing is not done automatically, it is more vulnerable to changes in the JSON text that it's parsing (perhaps I'm wrong about this).
  3. Writing code to parse JSON via a stream parser is ugly and tedious.
A: 

Guess you've pretty much answered your own question. :)
Using the built-in JSON parser myself and have never looked for an alternative.

alex
+2  A: 

I think question is whether built-in one is good enough. If it is, sure, minimizing dependencies is often a good strategy. Good enough can refer to both efficiency and ease of use.

For what it's worth, Jackson also has a decent tree model as well as full data binding. Tree model is significantly faster than default parser (parsing is 3x-5x faster on J2SE, probably similarly on other platforms like Android, tree model itself is probably more efficient as well). Or: if you don't want dependency to second jar (mapper is needed for tree model and data binding), writing your own tree to cover your use cases is simple too. Either use basic HashMap/ArrayList/wrappers, or have your own classes if you prefer. Builder would be maybe 40 lines of code top.

StaxMan