Thursday, October 6, 2011
Jersey Client API
Jersey Client API Implementation And Converting JSON String to object
Thank you.
Regards,
Kaleeswaran.S
Jersey Client API code receives json data from web service and converts received jason data to the corresponding object ..
Here the code goes ..
String BASE_URI = "http://localhost:8080/PhrescoServer/webresources/api";
BASE_URL specifies where my web service resides..
WebResource res = c.resource(BASE_URI);
com.sun.jersey.api.client.WebResource.Builder builder = res.accept(MediaType.APPLICATION_JSON_TYPE);
This code specifies it ll accept JSON type data and accepts it from web service.
Here the important coding which converts Json type to Object
Declare a generic type object.. Here list of technology is my object , to which i have to convert json string.
In web service i returned <List<Technology>> as JSON type data
GenericType<List<Technology>> genericType = new GenericType<List<Technology>>() {}
List<Technology> response = builder.get(genericType);
Above code Done it :)
for (Technology technology : response) {
System.out.println(technology.getType());
}
Happy Coding
-- Thank you.
Regards,
Kaleeswaran.S
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment