sentence
stringlengths 1
1.38k
| label
stringclasses 3
values |
---|---|
Which, if using the jsondriver and setting the proper settings, will encode ugly types into the actual json, so that you don't loose anything.
|
o
|
A small price to pay (ugly json) for true serialization.
|
n
|
Note that URL_http://wiki.fasterxml.com/JacksonHome [Jackson] fixes these issues, and is URL_https://github.com/eishay/jvm-serializers/wiki [faster] than GSON.
|
p
|
+1 I agree.
|
o
|
I find jackson or simple json much easier to use then gson.
|
p
|
Oddly, the only decent JSON processor mentioned so far has been GSON.
|
n
|
Here are more good choices:
URL_http://wiki.fasterxml.com/JacksonHome [Jackson] -- powerful data binding (JSON to/from POJOs), streaming (ultra fast), tree model (convenient for untyped access)
URL_http://flexjson.sourceforge.net/ [Flex-JSON] -- highly configurable serialization EDIT (Aug/2013): One more to consider:
URL_http://code.google.com/p/genson/ [Genson] -- functionality similar to Jackson, aimed to be easier to configure by developer .
|
p
|
The XStream library also supports JSON: URL_http://xstream.codehaus.org/json- tutorial.html [ URL_http://xstream.codehaus.org/json-tutorial.html ] .
|
o
|
If you visit URL_http://json.org/java/ [this-page] you will find several Java classes that can help with this.
|
o
|
For example, the JSONObject
and the JSONArray
classes.
|
o
|
They are designed to read in a JSON String and provide access to their properties via a get() method.
|
o
|
I used this library in a project and it stinks.
|
o
|
Example: JSONObject#getNames(JSONObject) returns null instead of an empty List or array if no names are available.
|
o
|
@Malax Thanks for the heads up.
|
o
|
Hopefully one of the other suggestions would work better for the OP.
|
o
|
@Malax Since you have access to the code, couldn't you change JSONObject#getNames to return whatever you'd like in that case?
|
o
|
But that JSON library could still stink for other reasons (never used them personally, but I know we're using them at work).
|
n
|
Well, json.org default lib is rather rudimentary.
|
n
|
I wouldn't choose it for any new project -- most alternatives from the page are much better.
|
o
|
People are just using it because it has been around for years, and so others have used, and recommend it to new users... basic s/w development inertia.
|
p
|
Or with Jackson: CODESNIPPET_JAVA1 .
|
o
|
If, by any change, you are in an application which already uses URL_http://restfb.com/ [ URL_http://restfb.com/ ] then you can do: CODESNIPPET_JAVA1 .
|
o
|
etc.
|
o
|
If you use any kind of special maps with keys or values also of special maps, you will find it's not contemplated by the implementation of google.
|
o
|
CODESNIPPET_JAVA1 .
|
o
|
Here's an option from my URL_http://northconcepts.com/data-pipeline/ [data- migration-library] that uses xpath plus the built-in, generic record class instead of creating a new bean class.
|
o
|
You can filter in java code, but here we use CODETERM1 which uses the expression language to auto-convert the CODETERM2 field from a string to a boolean and test if it's true.
|
o
|
You can get URL_https://northconcepts.com/data- pipeline/expression-language/ [more-info-on-the-expression-language-here] .
|
o
|
CODESNIPPET_JAVA1 .
|
o
|
The above code reads from a file, but you can easily read from a URL as in the following example that reads stock info from google.
|
o
|
URL_http://northconcepts.com/data-pipeline/examples/read-a-json-stream/ [ URL_http://northconcepts.com/data-pipeline/examples/read-a-json-stream/ ] Good hunting.
|
p
|
I use URL_http://www.jsonschema2pojo.org/ [this-tool] shown by @JigarJoshi to generate my schema.
|
o
|
Then I use GSON upon the generated classes.
|
o
|
Its very handy.
|
p
|
Input JSON and get Java classes:) .
|
o
|
What's wrong with the standard stuff?
|
o
|
CODESNIPPET_JAVA1 .
|
o
|
Give boon a try: URL_https://github.com/RichardHightower/boon [ URL_https://github.com/RichardHightower/boon ] It is wicked fast: URL_https://github.com/RichardHightower/json-parsers-benchmark [ URL_https://github.com/RichardHightower/json-parsers-benchmark ] Don't take my word for it... check out the gatling benchmark.
|
p
|
URL_https://github.com/gatling/json-parsers-benchmark [ URL_https://github.com/gatling/json-parsers-benchmark ] (Up to 4x is some cases, and out of the 100s of test.
|
o
|
It also has a index overlay mode that is even faster.
|
p
|
It is young but already has some users.)
|
o
|
It can parse JSON to Maps and Lists faster than any other lib can parse to a JSON DOM and that is without Index Overlay mode.
|
p
|
With Boon Index Overlay mode, it is even faster.
|
p
|
It also has a very fast JSON lax mode and a PLIST parser mode.
|
p
|
:) (and has a super low memory, direct from bytes mode with UTF-8 encoding on the fly).
|
n
|
It also has the fastest JSON to JavaBean mode too.
|
p
|
It is new, but if speed and simple API is what you are looking for, I don't think there is a faster or more minimalist API.
|
p
|
A better alternative to Jersey/Jackson for building JSON REST APIs?
|
o
|
I need to build the server side of a JSON-REST API, and I've been playing with Jersey to do it (using it's JSON-POJO mapping feature).
|
o
|
The problem is that even testing the simplest possible use-case has required several questions here on SO, and quite a bit of hunting around.
|
p
|
In short, it's not a very fluid API in the style of, say, JSoup, it appears to be a tool that comes from the era where everything was XML, and then it was retrofitted for JSON.
|
p
|
You can see this, for example, in the requirement that POJO objects need to be annotated with @XmlRootElement even though nothing I am doing involves XML.
|
o
|
I'm wondering if there are other libraries, perhaps more recent, that I should consider for this that might be easier to use than Jersey?
|
o
|
YES!
|
o
|
YES!
|
o
|
FOR THE LOVE OF GOD YES!
|
p
|
I have been asking this same type of question now over and over again and I keep getting little to nothing back.
|
n
|
I even gave up a 300pt bounty and still nothing: [here]( URL_http://stackoverflow.com/questions/6986365/java-rest-client-jax-rs - automatic-type-mapping).
|
o
|
[And this one was fun.
|
n
|
]( URL_http://stackoverflow.com/questions/6312030/cxf-no-message-body-writer - found-for-class-automatically-mapping-non-simple-r).
|
o
|
I don't know why we haven't got web services in java tied down yet.
|
o
|
Jersey can serialize POJOs to JSON without any annotations using Jackson.
|
o
|
You configure this by setting the CODETERM1 property to CODETERM2 .
|
o
|
In CODETERM3 , add the following servlet init parameter: CODESNIPPET_JAVA1 .
|
o
|
URL_http://jersey.java.net/nonav/documentation/latest/json.html#json.pojo.appr oach.section [See-the-Jersey-documentation] .
|
o
|
I highly recommend URL_http://www.jboss.org/resteasy [JBoss-RESTEasy] for the REST API.
|
p
|
I've used it on a couple of projects and found it to be trivial to setup.
|
n
|
It also integrates nicely with Spring if you need that.
|
p
|
I have used both Jackson and Gson for the JSON support with RESTEasy and it is quite simple.
|
p
|
All you do is annotate a POJO with JAXB annotations and include the proper libraries.
|
o
|
Another really great part of RESTEasy is the good support for multipart form data.
|
p
|
They provide an @MultipartForm annotation which allows you to bind a multipart form to a POJO without writing any code...works slick.
|
o
|
I would advise against Spring MVC for REST because it is not JAX-RS compliant.
|
n
|
Using a JAX-RS compliant interface gives you a little bit better portability if you decide to switch to a different implementation down the road.
|
n
|
Hmm, I'm not sure, it looks like it expects to be deployed in a war file, and I would rather avoid a heavyweight servlet container and all of that infrastructure, the API is just a small part of my project, I don't want to stuff the entire thing in a war just so I can support the API :-/.
|
n
|
Run it on Jetty...it will be light-weight!.
|
p
|
for converting json to pojos : URL_http://code.google.com/p/google-gson/ [gson] and URL_http://jackson.codehaus.org/ [jackson] .
|
o
|
For URL_http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework- reference/html/ch18s02.html [Restful] I'd use URL_http://blog.springsource.org/2009/03/08/rest-in-spring-3-mvc/ [spring] , or URL_http://www.restlet.org/ [restlet] .
|
o
|
Yes, I'm very familiar with Gson, and Jersey already uses Jackson, but converting JSON to and from POJOs is only one part of the problem, I'm looking for an alternative to Jersey, which is a framework for building REST-HTTP APIs.
|
o
|
If one existed I'd prefer a HTTP framework that worked with Gson instead of Jersey as I'm more comfortable with it.
|
p
|
@sanity oh, spring then.
|
p
|
Note:
I'm the URL_http://www.eclipse.org/eclipselink/moxy.php [EclipseLink-JAXB-(MOXy)] lead, a member of the URL_http://jcp.org/en/jsr/detail?id=222 [JAXB-(JSR-222)] expert group and a contributor to the URL_http://jersey.java.net/ [Jersey] project.
|
o
|
With Jersey or any JAX-RS project you can use a CODETERM1 / CODETERM2 for complete control over your JSON binding.
|
o
|
Below is an example of using this mechanism to leverage MOXy as the JSON provider.
|
o
|
URL_http://stackoverflow.com/questions/8980204/configuring-cxf-with-spring-to-use-moxy-for-xml-marshalling-unmarshalling/8989659#8989659 [Configuring-CXF-with-Spring-to-use-MOXY-for-XML-marshalling/unmarshalling] .
|
o
|
As URL_http://stackoverflow.com/a/9503506/27657 [NimChimpsky-mentioned] restlet will do this out of the box.
|
o
|
Furthermore, if your client is also java you can abstract the functionality into an interface and wrap it with a client side proxy fairly easily.
|
o
|
This tutorial page shows how to do what I've mentioned URL_http://wiki.restlet.org/docs_2.0/13-restlet/21-restlet/318-restl et/303-restlet.html [here] .
|
o
|
You can try URL_http://openjpa.apache.org/jest.html [JEST] , it works over URL_http://openjpa.apache.org/ [OpenJPA] .
|
p
|
Json conversion.
|
o
|
i want to create a Json like this CODESNIPPET_JAVA1 .
|
o
|
i have tried below code but that create Json just only for one line CODESNIPPET_JAVA2 .
|
o
|
this above code create Json like this CODESNIPPET_JAVA3 .
|
o
|
Please let me know about the changes required in that Java code thanks.
|
o
|
Change your code as: CODESNIPPET_JAVA1 .
|
o
|
Thanks for reply; but it gives error "The method toJSONString() is undefined for the type JSONObject" at jsonArray.push(jsonObj.
|
o
|
_toJSONString()_);.
|
o
|
@ShYzDaSE : see my edit answer.
|
o
|
O yes done thank You very Much Imran Saved alot of my time :-) stay blessed buddy.
|
p
|
why you are converting jsonarray to JSONObject?
|
o
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.