I'm tryin to consume this REST service
@POST
@Path(value="/storeGeneric")
@Consumes(MediaType.APPLICATION_JSON)
public <T> void storeGeneric(T data) {
try {
System.out.println("data name: "+data.getClass().getCanonicalName());
...
} catch (Exception e) {
e.printStackTrace();
}
}
by passing a JSON object by this javascript function:
function sendArticolo() {
var articolo = {};
articolo.id = 1;
articolo.prezzo = 1;
articolo.descrizione="roba";
try {
$.ajax({
url: 'http://localhost:8080/ZZCrudRest/services/Rest/storeArticolo',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(articolo),
dataType: 'json'
});
} catch (err) {
alert(err.message);
}
}
but, I got this exception:
12:37:26,294 GRAVE [com.sun.jersey.spi.container.ContainerResponse] (http-127.0.0.1-127.0.0.1-8080-1) The RuntimeException could not be mapped to a response, re-thr
owing to the HTTP container: java.lang.ClassCastException: java.lang.reflect.Method cannot be cast to java.lang.Class
at com.owlike.genson.reflect.TypeUtil.getTypes(TypeUtil.java:362) [genson-0.94.jar:]
at com.owlike.genson.reflect.TypeUtil.match(TypeUtil.java:298) [genson-0.94.jar:]
at com.owlike.genson.convert.BasicConvertersFactory.provide(BasicConvertersFactory.java:102) [genson-0.94.jar:]
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:74) [genson-0.94.jar:]
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:56) [genson-0.94.jar:]
(more and more...)
Is there a way to consume a REST service with a generic parameter using JSON? I googled a lot without success. I'm using Jersey 1.8, genson 0.94, jboss 7.1.