Friday, February 21, 2014

Jersey REST retrieve List of custom object

It took me while to understand how one require to  retrieve generic object from ClientResponse.

I had an array of objects in Json format as a response of an REST api, which I was trying to deserialize it into List<CustomObject> refer.

	ClientResponse rsp = webresource.path(id.toString()).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
	List<CustomObject> list = rsp.getEntity(new GenericType<List<CustomObject>>(CustomObject.class));


But I kept on getting following Error:

Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of test.CustomObject out of START_ARRAY token
 at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@3488b1e6; line: 1, column: 1]
	at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)


Issue got solved with following way


	ClientResponse rsp = webresource.path(id.toString()).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
	List<CustomObject> list = rsp.getEntity(new GenericType<List<CustomObject>>(){});


10 comments:

  1. Thanks very much!

    ReplyDelete
  2. Is your group playing your sibling's group? Bring your canine along as good help and ensure he has his most loved jersey on.
    Greg Bird jersey

    ReplyDelete
  3. So, if you want to purchase a jersey that represents a specific player on a specific team, the number will be chosen for you essentially.make your own jersey shirt

    ReplyDelete
  4. These occasions are both representative of instances where Jersey Barriers have been incredibly useful in overall, general public safety. imprints-tshirt

    ReplyDelete
  5. Running pants and underpants must be a strong shading and all colleagues must have comparable hues. Basketball shorts

    ReplyDelete
  6. The color of uniform is mostly selected only after thorough discussions with the team. Basketball uniforms

    ReplyDelete
  7. The heat press that I and a few other business tee shirt printers use permits the temperature, time and strain to be set. This gives a perfect press time after time.
    custom shirts cheap

    ReplyDelete
  8. It is additionally imperative to know whether you have hard or delicate water. This is in such a case that you have hard water, it won't expel the dirt like it is assume to. Basketball uniforms

    ReplyDelete
  9. It doesn't make a difference how you wear it, it doesn't make a difference when you wear, everything what makes a difference is that you're doing it for the game that you love and that's it.
    Basketball shorts

    ReplyDelete