我正在尝试使用此 REST 服务
@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();
}
}
通过这个 javascript 函数传递一个 JSON 对象:
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);
}
}
但是,我得到了这个例外:
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...)
有没有办法使用 JSON 来使用带有通用参数的 REST 服务?我用谷歌搜索了很多但没有成功。我正在使用 Jersey 1.8、genson 0.94、jboss 7.1。