user3683358
user3683358

Reputation: 21

Converting JSON String to Java Object with jersey

I am new to REST , JSON and Jersey usage. Now we got a requirement where we need to implement a Client which need need to query the server with JSON request, GET and going to receive a JSON String/Object, which need to be parsed and converted into local datastructure.

Could someone help me for the below points?

  1. What I need to download for implementing REST Client application for supporting JSON ( we have restrictions to use Jersey apis, and no other third-party apis)

  2. Sample java client code for requesting and parsing the JSON data.

Upvotes: 2

Views: 5798

Answers (2)

Anik
Anik

Reputation: 471

If you want to convert String to a JSONObject -

Use this library - http://www.json.org/java/

JAR file is available at http://code.google.com/p/org-json-java/downloads/list

Use below code to convert a string to JSONObject -

 JSONObject final_result = new JSONObject(result);

Upvotes: 0

Kraiss
Kraiss

Reputation: 999

"What do I need ?", It really depends of the technology you want to use with it .. eg, if you use glassfish (netbeans server), you can use their jersey "org.glassfish.jersey.jackson.JacksonFeature" as json provider and the other ressources glassfish includes. You won't need anything else for a simple implementation.

As you are a beginner, you better follow a tutorial like this one : http://java.dzone.com/news/simple-restful-web-services

Upvotes: 1

Related Questions