views:

32

answers:

1

Hi, Typically I have been using xml web services and have used JAXB for marshalling/unmarshalling the xml. In this case, I have an xml schema for generating the classes and then at runtime I simply deal with java objects and not with xml since that unmarshalling is done under the covers for me.

What sort of libraries exist for doing something similar in json? I have to make an http Get call that returns a list of json objects and I am not sure what my java client should look like. What are the best practices here?

Thanks.

A: 

There are a lot of Java libraries out there that parse JSON. The simplest one to use is the one by org.json. For a list of various JSON parsing libraries take a look at (http://json.org)

If you have used JAXB to marshall / unmarshall value objects (POJO's) then you can also take a look at Jackson which uses JAXB annotations to determine what your POJO's representation in JSON should look like. (http://jackson.codehaus.org/)

Essentially you would need to make a HTTP GET request for your JSON, parse the request using a JSON parser and convert them into a convenient representation in Java. You can use the Apache Commons HttpClient libraries and JSON parsers in conjunction.

Rahul