0
嗨,我有以下类别:Java泛型和杰克逊映射
public class MyRequest {
}
和
public class MyResponse {
}
和
public class Request<T> {
private String code;
private T request;
public setCode(String code) {
this.code = codel
}
public setRequest(T request) {
this.request = request
}
}
和跟踪服务请求的方法:
public MyResponse getMyResponse(Request<MyRequest> myRequest) {
//process
try {
ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(myRequest);
System.out.println(jsonInString);
} catch(Exception exp) {}
}
以下的Json请求是从JavaScript发送的;
{
"code":"TESTCODE",
"request":null
}
我发送请求后,我得到一个无效的Json错误。任何人都可以告诉我什么是我的请求错误JSON或其他错误..?
如果你是积极的,通用实际上不是空,你的问题是反序列化。这将有助于:http://stackoverflow.com/questions/11664894/jackson-deserialize-using-generic-class – Eric
其中是JavaScript的反序列化您的JSON的代码? – Coder
使用Firefox的HTTP请求附件发送此内容。这不是一个完整的代码...以前的代码没有Java泛型是完美的工作..也是杰克逊用于春天.. – Adds