Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I convert received JSON data back into a list of objects?

1002901Apr 13 2013 — edited Apr 16 2013
I'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

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 14 2013
Added on Apr 13 2013
2 comments
2,068 views