ste*_*ios 1 jax-rs jersey-2.0 javax.ws.rs
我正在尝试将jax-rs响应序列化为json字符串.
来自服务器的响应是json,我从泽西客户端获得它:
Response resp = target.request().method("PUT", Entity.json(payloadBean))
Run Code Online (Sandbox Code Playgroud)
其中payloadBean是我的json请求.一切正常但我无法转换json字符串中的resp以便记录它.
如果我尝试:
String s = EntityUtils.toString((HttpEntity) resp.getEntity());
Run Code Online (Sandbox Code Playgroud)
我明白了:
org.glassfish.jersey.client.internal.HttpUrlConnector cannot be cast to org.apache.http.HttpEntity
Run Code Online (Sandbox Code Playgroud)
顺便说一句,如果我没有强制转换为HttpEntity,编译器说:
toString (org.apache.http.HttpEntity) in EntityUtils cannot be applied to (java.lang.Object).
Run Code Online (Sandbox Code Playgroud)
我的相关进口是:
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
使用 resp.readEntity(String.class)
public abstract <T> T readEntity(Class<T> entityType)
类型参数:
T
- 实体实例Java类型.参数:
entityType
- 实体的类型.使用MessageBodyReader将消息实体输入流作为指定Java类型的实例读取,该消息支持将消息实体流映射到请求的类型.
归档时间: |
|
查看次数: |
6872 次 |
最近记录: |