sentence
stringlengths
1
1.38k
label
stringclasses
3 values
Most also do not fully support the use of Java Generics.
o
Gson considers both of these as very important design goals.
o
Check out if your version of Java already contains JSON API - see URL_http://www.oracle.com/technetwork/articles/java/json-1973242.html [Java- API-for-JSON-Processing,-July-2013] and URL_https://jcp.org/en/jsr/detail?id=353 [JSR-353] .
o
+1.
o
Gson is great.
p
Here's an use example: URL_http://stackoverflow.com/questions/1688099/converting-json-to - java/1688182#1688182.
o
This is the solution I went with in the end, and months later I'm very happy with my decision.
p
The problem with Gson (at least in versions up to 1.4) is that it is not able to handle circular references.
o
This is very common in some scenarios (JPA/JDO objects being serialized to JSON...).
o
Most java json libs do not deal with cyclic deps -- that's more domain of object serialization frameworks.
o
FWIW, XStream with Badgerfish (jettison) does handle them (since it's full object-serialization framework, although resulting json looks ugly, as its xml based, just converts to json via badgerfish).
n
GSon uses the same design protocol JSON.org went with when developing JSONObject and JSONArray.
o
Design protocol meaning... ?
o
Similar API, or something?
o
I don't see much similarities between the two (which I think is good thing for GSON).
p
Gson is great, and has high quality documentation too.
p
Check out the [User Guide]( URL_http://sites.google.com/site/gson/gson-user-guide ) to get started.
o
GSON is awesome, brings a python like feel to Java, well, atleast for JSON purposes.
p
When I wanted to use JSONLib; I found out that the jar file that is available in URL_http://json-lib.sourceforge.net has some class dependencies and it needs to be used by some other jar files, that contain that classes.
o
So I used Gson.
o
Incredibly, GSON types [don't implement Serializable nor Cloneable...]( URL_http://code.google.com/p/google-gson/issues/detail?id=485) .
n
Really too bad.
n
GSON is a good library, we have been using it in our project from past 2years, and it works fine.
p
Gson is very slow.
n
I've a situation with a client that makes use of gson that converts, 300 objects at a time, from json to objects with gson and there are about 9-50k objects to convert.
o
This takes 10-60 minutes on a mobilephone/hand held computer.
o
@Johan What would be more reasonable performance and what other libraries deliver?
o
@eflat it seems to depend on object size and how you handle the mobile phone memory etc, not only gson/jackson etc.
n
However, Jackson performed better for us.
o
I've used URL_http://json-lib.sourceforge.net/ [JSONLib] , URL_http://flexjson.sourceforge.net/ [FlexJSON] and URL_http://code.google.com/p/google-gson/ [Gson] all with great success.
p
Each has its best use.
o
JSONLib is awesome as a core JSON library when you just want to process all elements of a JSON.
p
CODESNIPPET_JAVA1 .
o
FlexJSON shines with its deepSerialize method that can properly handle serializing all get methods presented in a bean obtained from Hibernate (lazy loaded).
p
CODESNIPPET_JAVA2 .
o
Gson seems to be the best API to use when you want to convert a json to a Java class.
p
Other API only call set methods on the high level classes in the bean structure.
o
If you have a deep bean structure, everything else will be implemented with dyna beans.
o
Causes havoc elsewhere.
o
Gson fully populates all low level values by calling all set methods for all data found in the JSON.
n
CODESNIPPET_JAVA3 .
o
URL_http://en.wiktionary.org/wiki/your_mileage_may_vary [YMMV] .
o
"Gson fully populates all low level values by calling all set methods for all data found in the JSON."
n
Actually, Gson does not use set methods when deserializing (nor does it use get methods when serializing).
o
Instead, Gson uses reflection to directly reference the fields.
o
Some future version of Gson will reportedly support using getters/setters instead of fields.
o
A comment on issue 232 includes the possible changes necessary to enable getter support.
o
When I wanted to use JSONLib; I found out that the jar file that is available in URL_http://json-lib.sourceforge.net has some class dependencies and it needs to be used by some other jar files, that contain that classes.
o
So I used Gson.
o
I can't _truly_ recommend this, because I've never used it, but URL_http://jackson.codehaus.org/ [Jackson] sounds promising.
p
The main reason I mention it is that the author, Tatu Saloranta, has done some really great stuff (including URL_http://woodstox.codehaus.org/ [Woodstox] , the StAX implementation that I use).
p
UPDATE: A year ago I started actually using Jackson and I can confirm that it is awesome :-).
p
I especially like being able to switch back and forth between using a "tree model" (similar to XML DOM) and object mapping.
o
For example, let's say I have the following JSON: CODESNIPPET_JAVA1 .
o
The data I really want is inside CODETERM1 .
o
The rest is fluff that I don't care about (maybe returned by some REST API).
o
In addition, I have the following Java class: CODESNIPPET_JAVA2 .
o
I can use the following code to navigate through the JSON document and then map the object I want: CODESNIPPET_JAVA3 .
o
Without this capability, I would be stuck writing extra wrapper classes.
o
Another impressive Jackson feature is the ability to _map classes that you don't own_ (in other words, map a third-party Java class when you can't change the source code).
p
See URL_http://www.cowtowncoder.com/blog/archives/2009/08/entry_305.html [this- blog-entry] for more details.
o
Jackson is amazingly customizable.
p
I could list many, many more features :-).
o
Finally, don't miss URL_http://www.cowtowncoder.com/blog/archives/2010/11/entry_434.html [7 -Killer-Features-that-set-Jackson-apart-from-competition] .
o
I second that, Jackson is a wonderful piece of work- much more efficient.
p
Just curious - why the downvote?
o
Does someone have different (i.e.
o
negative) feedback about Jackson?
o
I tried Jackson when I was doing interoperability between .NET and Java and dates was a mess for me.
n
I don't understand why it's done the way it's done in Jackson.
o
The idea behind JSON is that I should just be able to shuffle data around, I don't have to care about date formats, timezones and all that crap.
o
When I was sending data back and forth between js and c# I had zero problems whatsoever.
o
Hi Anders!
o
JSON does not have a Date type (just strings, numbers, booleans), and each lib therefore has to define its own convention.
o
That can lead to interoperability problems, esp.
p
since default serializations for different languages are different.
o
One thing that might be interesting wrt Jackson is the performance aspect (Jackson is specifically designed as a very high performance JSON package), see [ URL_http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking ] and [ URL_http://www.cowtowncoder.com/blog/archives/2009/09/entry_326.html ].
p
I've just ran into some problems with Jackson, Hibernate and Spring, however, I don't know if this issue is related to Jackson or Spring or Hibernate ... see URL_http://stackoverflow.com/questions/3325387/infinite-recursion-with - jackson-json-and-hibernate-jpa-issue.
o
user268098: I think most Java JSON handling libraries have issues with cyclic dependencies, and most have some ways to either exclude just references, or handle them with annotations (I added an answer in the other question to point out one way to do that with Jackson).
o
Of alternatives I think only XStream+Jettison handles cyclic dependencies automatically, if enabled.
o
I second this.
o
Jackson is also easy to use.
p
See: URL_http://spring-java - ee.blogspot.com/2010/12/how-to-dumpinspect-object-or-variable.html.
o
I have used Jackson a lot, and it blows the competition away.
n
FYI, it appears that Jackson has moved to a new home within codehaus.org.
o
Can you update your original link?
o
To wit: URL_http://jackson.codehaus.org/ .
o
I second Jackson in favour of FlexJson; FlexJson lacks a default Jax-RS provider and doesn't correctly parse generics (like SomeObject).Also Jackson has very elegant configuration (once you find out how to plug it in!)
p
and mixins allow great flexibility!.
p
Just went through this exercise.
o
I wanted to represent arbitrary JSON as nearest Java equivalent.
o
For me that is a HashMap/ArrayList Object.
o
URL_http://code.google.com/p/json-simple/ [json-simple] was excellent: tiny, with a simple API that generates HashMap/ArrayList with a single call.
p
It also has extensions for object serialization/deserialization.
o
I also tried gson: API was very object serialization oriented, and type safe, could not do what I needed simply.
o
+1 The way it encodes/decodes to maps, lists and primitive objects appeals to my Python experience too.
o
FWIW, almost all Java JSON libraries support this conversion mode, including GSON, Jackson and Genson.
o
I can recommend URL_http://json-lib.sourceforge.net/ [ URL_http://json - lib.sourceforge.net/] .
p
We have used it in few projects without problems.
o
This bug has made me sad: URL_http://sourceforge.net/tracker/?func=detail&aid=2062 744&group_id=171425&atid=857928.
n