How do I convert received JSON data back into a list of objects?
1002901Apr 13 2013 — edited Apr 16 2013I'm new to JSON.
This is my client code:
public <T> T getStuff(Class<T> responseType) throws UniformInterfaceException {
WebResource resource = webResource;
resource = resource.path("stuff");
return resource.accept(javax.ws.rs.core.MediaType.APPLICATION_JSON).get(responseType);
}
What I'm calling is this (this is on the server side):
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/stuff")
public Response getStuff() {
return Response.ok(ProjectProperties.stuff).header("Access-Control-Allow-Origin", "*").build();
}
Just FYI (This is what the server-side code is fetching):
public static List<Object> stuff= new CopyOnWriteArrayList<Object>();
==================================================
The above is all good and well...
It's the getting of the data that is failing me.
I try this (from my client code, in hope to start using the data):
RestClient rc2 = new RestClient();
List list;
try {
list = rc2.getStuff(List.class); // RESTFUL
} catch (UniformInterfaceException uie){
System.out.println("The data isn't received properly yet.");
uie.printStackTrace();
}
And I get this:
// SEVERE: A message body reader for Java class java.util.List, and Java type interface java.util.List, and MIME media type application/json was not found
// SEVERE: The registered message body readers compatible with the MIME media type are:
Any idea what I'm doing wrong?
Again, the List of object is turning into JSON, then I receive it... I just need to turn it back into a list of objects, so I can use it.
Please help,
Thanks, Robert