tags:

views:

614

answers:

3

Can anyone post feedback on their experiences with various json libraries for java? In particular, does anyone have feedback on their experience with Google-gson?

(I'm aware that there's a nearly identical question here, but that's over a year old, so people may have different experiences now.)

+1  A: 

I've used:

http://www.json.org/java/index.html

on a couple of projects. It's lightweight and efficient, and has stream-based handling for I/O.

mrp
Watch out for its bogus license, though.
Jonathan Feinberg
And answer is somewhat bogus too :).Json.org's lib is not efficient in any way (and light-weight only if you count size of code itself). It's not the slowest, just rather inefficient (see [http://www.cowtowncoder.com/blog/archives/2009/02/entry_204.html] for some numbers).Nor does it have streaming capabilities, as far as I see.
StaxMan
+3  A: 

We use GSON here. It's really simple to use and satisfies all our needs, we have basically the following, nothing more is needed:

/**
 * Write given Java object as JSON to the output of the current response.
 * @param object Any Java Object to be written as JSON to the output of the current response. 
 * @throws IOException If something fails at IO level.
 */
public void writeJson(Object object) throws IOException {
    String json = new Gson().toJson(object);
    this.response.setContentType("application/json");
    this.response.setCharacterEncoding("UTF-8");
    Writer writer = null;

    try {
        writer = this.response.getWriter();
        writer.write(json);
    } finally {
        close(writer);
    }
}

Our choice for GSON was based on the fact that its ideology fits our requirements, especially the full support of generic types. Besides that all it's also very performant.

BalusC
I assume that by 'very performant' you mean 'fast enough for my use cases'?This because results I have seen (like [http://www.cowtowncoder.com/blog/archives/2009/12/entry_345.html]) do not really suggest stellar performance.
StaxMan
@Stax: Jackson is simply *extremely* performant :) Besides, don't forget that Gson does/can more than only serializing. It also maps from/to collections/maps/generics/javabeans without any extra own code.
BalusC
+1  A: 

This is my favorite,

http://code.google.com/p/json-simple/

ZZ Coder