我现在阅读了几篇关于使用jax rs的泛型主题的文章,但我仍然无法使这个简单的例子起作用:
基本响应类:
@XmlRootElement(name="Base")
public class BaseMessage<T> {
private String success = "success";
private T data;
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
服务:
public Response search(final String searchTerm) {
// Some DB stuff
final Collection<SearchResult> filteredResults = dao.search(searchTerm);
// Construct answer with some data payload
final BaseMessage<Collection<SearchResult>> base = new BaseMessage();
base.setData(filteredResults);
final GenericEntity entity = new GenericEntity<BaseMessage<Collection<SearchResult>>>(base){};
return Response.ok(entity).build();
}
这总会导致: 发生了JAXBException:类java.util.ArrayList或它的任何超类都是这个上下文已知的。
我在这里缺少什么? CXF版本:3.1.14