【发布时间】:2014-02-24 13:38:32
【问题描述】:
我已经使用 JERSEY 1.5 设计了所需的 REST 服务,使用声明的接口如下:
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public IMyDTO doIt(ICustomer customer) {
return MySupport.createDTO(customer);
}
如果我尝试使用 JERSEY 1.5 Client API 调用此服务,则会出现以下错误:
无法构造 test.ICustomer 的实例,问题:抽象类型要么需要映射到具体类型,要么具有自定义反序列化器,要么使用额外的类型信息进行实例化
目前我由客户指定这样的参数:
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING,
Boolean.TRUE);
Client client = Client.create(clientConfig);
WebResource webResource = client.resource(restResource);
ClientResponse response = webResource.path(restResourcePath)
.type(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.post(ClientResponse.class, customer);
if (response != null) {
if (response.hasEntity()) {
result = response.getEntity(IMytDTO.class);
}
....
。 ICustomer 和 IMyDTO 是 java 接口,没有 任何 jackson 注释。实现也没有杰克逊注解。
我的问题:如果使用 REST 服务(客户端),如何(反)序列化对象?
我不会更改 java 接口并使用服务和客户端的实现...
【问题讨论】: