【发布时间】:2016-03-04 02:51:24
【问题描述】:
我刚刚创建了一个 jax-rs 服务,我正在尝试将从服务获得的字符串转换为实体。虽然使用 jax-rs 一切都是在服务器端自动完成的,但我认为也有可能在客户端完成它,但我没有找到它。
public class MyClient {
public static void main(String[] args) {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://localhost:8080/restapp/api/paints/1");
Response response = target.request().get();
Paint values = response.readEntity(Paint.class);
response.close();
}
}
这给了一个e:
Exception in thread "main" javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class client.Paint
(它适用于字符串)。
【问题讨论】:
-
你有 JSON 提供者吗?
-
@peeskillet 我只是对客户端应用程序有 resteasy 客户端依赖项。但是我没有在服务器端添加提供者之类的东西,所以我对你的问题有点困惑。
-
你用的是什么服务器?如果您使用的是 Wildfly,它已经有提供程序。
-
@peeskillet 确实是这样,谢谢!顺便说一句,我可以用一块石头杀死两只鸟,你知道我如何将
readEntity(Paint.class)转换为接受 Paint 对象列表吗?
标签: web-services rest jax-rs resteasy rest-client