sentence
stringlengths
1
1.38k
label
stringclasses
3 values
also, it has dependencies.
o
I have no personal experience with the following approach,but it could make sense to consider: URL_http://xstream.codehaus.org/index.html [XStream] (xml <-> java data binding) with URL_http://jettison.codehaus.org/ [Jettison] driver (xml<->json mapper), more details are available URL_http://xstream.codehaus.org/json- tutorial.html [here] .
o
That's from their site: CODESNIPPET_JAVA1 .
o
JAXB 2.0 also has support for JSON serialization using Jettison.
o
Actually, any XML package that can use Stax API can use Jettison -- JAXB does, so there's no extra work involved (same is mostly true for XStream too, although it may have some additional support).
o
I found XSteam useful when converting Objects back and forth between Java & XML or JSON with the Jettison driver.
o
If you want to influence the representation in XML/JSON to a larger degree than just naming tags and ignore properties, you'll be better of using one of the other libraries mentioned above.
o
Isn't this a little perverse?
o
Gson can also be used to serialize arbitrarily complex objects.
n
Here is how you use it: CODESNIPPET_JAVA1 .
o
Gson will automatically convert collections to JSON arrays.
o
Gson can serialize private fields and automatically ignores transient fields.
o
While deserializing, Gson can automatically convert JSON arrays to collections or arrays.
o
Gson uses the specified class as the primary specification for deserialization.
o
So, any extra fields available in the JSON stream are ignored.
o
This helps design secure systems that prevent injection attacks.
p
You can also extend Gson's default serialization and/or deserialization behavior by registering custom type adapters.
o
For more details: see the user guide at the project: URL_http://code.google.com/p/google-gson/ [ URL_http://code.google.com/p/google - gson/] Disclosure: I am one of the co-authors of Gson.
o
And yet another example is here: URL_http://stackoverflow.com/questions/2496494 /library-to-encode-decode-from-json-to-java-util-map/2496528#2496528.
o
Any plans to support circular dependencies in the near future?
o
You can file a feature request for the project, if there isn't one.
o
I know many developers would like to have this.
o
I've been meaning to try URL_http://flexjson.sourceforge.net/ [Flexjson] .
o
It looks like it uses reflection on bean-style properties and uses similar rules as Hibernate/JPA lazy-loading for serialization, so if you give it an object to serialize it will leave out collections (unless you tell it to include them) so you don't end up serializing the entire object graph.
o
The json.org library does pretty well with serializing basic beans with reflection, but doesn't have these advanced features.
p
Might be worth checking out, especially if you use an ORM solution.
p
I like FlexJSON as well and even modified it to be compatible with Microsoft's JSON serializer really easily.
p
You may try using GSON.It's downloadable at URL_http://google- gson.googlecode.com/files/google-gson-1.4-release.zip [ URL_http://google - gson.googlecode.com/files/google-gson-1.4-release.zip] Quite simple to use actually.I used it to parse JSON results from Yelp and there is a simple example here: CODESNIPPET_JAVA1 .
n
Hi, based on ur experience, is the GSON support JDK1.4 by any chance?
o
I can't find the documentation re the JDK it supports.
o
Thanks.
o
I've used URL_http://jsontools.berlios.de/ [JSON-Tools-library] and it works well.
p
works I was looking for a very simple way to do Php json encode in (server) and Java json decode (client), all seems too much to do only to achieve this.
p
I came out to this which is really simple and it works perfect.
p
Please see: URL_http://stackoverflow.com/questions/3831680/httpservletrequest-get-post- data/5539252#5539252 [more-details-click-here] .
o
I recommend URL_http://code.alibabatech.com/jira/browse/FASTJSON [fastjson] ,just as its name,really fast .
p
I wrote a JSON "pull-api" parser (3 classes, 18K), which I really like using.
o
I find the pull metaphor much more usable than the event metaphor, and creating a document tree using pull is trivial.
n
FWIW I didn't much care for the www.json.org parser either.
o
My biggest complaint with the offerings out there is the size of them - we target a download-constrained applet market.
o
I remember lying in bed one night at about 2am wondering "how hard could it be", after a bit I got up and started writing - URL_http://www.softwaremonkey.org/Code/JsonParser [this-tiny-parser-is-the- result] .
o
JSON Tools looks good too.
p
The following generalized recursive code uses my parser to parse a JSON file into a "DataStruct" - essentially a map of lists (Note that DataStruct and Callback are objects from another package which are not published with this parser: CODESNIPPET_JAVA1 .
p
crtmbrcbk.invoke(crtprm,psr,tgt,nam,psr.getMemberValue()); What are you, Polish?
o
:) Joking, of course.
o
I liked URL_http://sourceforge.net/projects/json2java/ [J2J---Json2Java] from Sourceforge.
o
Really easy to map JSON to almost any java object by only annotating the class using JsonElement and then passing the java and class to JsonReader like: CODESNIPPET_JAVA1 .
p
After exploring and actually using most of the major libraries listed here, I ended up writing a simplified API that is much easier to use and more fun to work with: URL_http://sharegov.blogspot.com/2011/06/json-library.html [ URL_http://sharegov.blogspot.com/2011/06/json-library.html ] .
n
I will add one more tip for excelent JSON<->JAVA binding lib PoJSON, it is written specifically for the URL_http://netbeans.org [NetBeans-IDE] (by Petr Hrebejk) and thus it is used in production on large project.
o
It is easy to use in any project, it is just not placed on the web as a separate project (afaik), however it is in a separate package "org.codeviation" here: URL_http://hg.netbeans.org/main/file/9609b899e64d/kenai/src/org/codeviation [ URL_http://hg.netbeans.org/main/file/9609b899e64d/kenai/src/org/codeviation ] .
p
I've used URL_http://jettison.codehaus.org/ [Jettison] and it works well.
p
A nice new library for Java is URL_http://code.google.com/p/serotonin-json/ [Serotonin-JSON] .
p
It has lots of nice features.
p
I say "new", but it's really been around for years, just not as open source.
p
You might want to list some of the nice features, since there are so many alternatives -- project page lists many, although most exist in other libs as well.
p
I have developed an Add-on for Android's in-built JSON Parser (or.json.
o
), which helps to convert JSON to Java Object- URL_http://prasanta- paul.blogspot.com/2011/04/json-to-java-bean-conversion-for.html [http ://prasanta-paul.blogspot.com/2011/04/json-to-java-bean-conversion-for.html] .
o
Converting JSON to Java.
o
I want to be able to access properties from a JSON string within my Java action method.
o
The string is available by simply saying CODETERM1 .
o
Below is an example of what the string can look like: CODESNIPPET_JAVA1 .
o
In this string every JSON object contains an array of other JSON objects.
o
The intention is to extract a list of IDs where any given object possessing a group property that contains other JSON objects.
o
I looked at Google's Gson as a potential JSON plugin.
o
Can anyone offer some form of guidance as to how I can generate Java from this JSON string?
o
_I looked at Google's Gson as a potential JSON plugin.
o
Can anyone offer some form of guidance as to how I can generate Java from this JSON string?_ URL_http://code.google.com/p/google-gson/ [Google-Gson] supports generics and nested beans.
o
The CODETERM1 in JSON represents an array and should map to a Java collection such as URL_http://docs.oracle.com/javase/6/docs/api/java/util/List.html [CODETERM2] or just a plain Java array.
o
The CODETERM3 in JSON represents an object and should map to a Java URL_http://docs.oracle.com/javase/6/docs/api/java/util/Map.html [CODETERM4] or just some JavaBean class.
o
You have a JSON object with several properties of which the CODETERM5 property represents an array of nested objects of the very same type.
o
This can be parsed with Gson the following way: CODESNIPPET_JAVA1 .
o
Fairly simple, isn't it?
o
Just have a suitable JavaBean and call URL_http ://google-gson.googlecode.com/svn/tags/1.3/docs/javadocs/com/google/gson/Gson.
o
html#fromJson%28java.lang.String,%20java.lang.Class%29 [CODETERM6] .
o
See also: URL_http://json.org/ [Json.org] - Introduction to JSON URL_https://sites.google.com/site/gson/gson-user-guide [Gson-User-Guide] - Introduction to Gson .
o
Thanks BalusC, I used Gson and the concept is quite simple to grasp.
p
Performant?
o
Have you actually measured it?
o
While GSON has reasonable feature set, I thought performance was sort of weak spot (as per [ URL_http://www.cowtowncoder.com/blog/archives/2009/09/entry_326.html])As to example: I thought GSON did not really need setters, and was based on fields.
o
So code could be simplified slightly.
o
It is fast enough, sure if you see what it all can do with javabeans, nested javabeans and generics.
p
The javabean getters/setters have other purposes in other layers and does not slowdown so I would just keep them there.
o
I use it in an android app.
o
It is not the fastest possible solution but it is simple enough to program to justify the lack of performance for the user until now.
p
Maybe in a later version of the app it will be removed for a faster solution.
p
Wrt speed, if it's fast enough, it's fast enough.
p
I just commented on reference to expected good performance.Feature-set wise Jackson handles all the same nesting, layering, generics, so that's not where speed difference comes from.Having getters and setters does not impact performance in any measurable way (for packages I am aware of), so definitely can have them there.
p
what is Data here?
o
Do I need to create any class?
o
?
o
@Fahim: scroll down in the code example.
o
@BalusC : Actually I need to convert mysql data to json (xml) and vice-versa.
o
Any link?
o
+1 for the "package com.stackoverflow.q1688099;".
o
For some reason it made me chuckle.
o
Bewaaaaare of Gson!
o
It's very cool, very great, but the second you want to do anything other than simple objects, you could easily need to start building your own serializers (which isn't _that_ hard).
p
Also, if you have an array of Objects, and you deserialize some json into that array of Objects, the true types are LOST!
n
The full objects won't even be copied!
o
Use XStream..
o