我有以下REST请求:
@GET
@Path("/test2")
public Response test2() {
List<StringEntity> out = new ArrayList<StringEntity>();
out.add(new StringEntity("blah"));
out.add(new StringEntity("blah"));
out.add(new StringEntity("blah"));
return Response.ok(new ObjectListResponse(out)).build();
}
我的客户得到了这个回复:
{[{value:"blah"},{value:"blah"},{value:"blah"}]}
我需要:
{["blah","blah","blah"]}
但是,我不能使用String。
我需要将我的班级 StringEntity 解析为字符串
public class StringEntity {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
答案 0 :(得分:0)
让框架为您完成工作。或者你必须使用StringEntity
类吗?
@GET
@Path("/test2")
@Produces(MediaType.APPLICATION_JSON)
public List<String> test2() {
List<String> out = new ArrayList<String>();
out.add("blah");
out.add("blah");
out.add("blah");
return out;
}
如需转换,请查看this
MessageBodyWriter
应该是你的朋友。