我有低于此下载与内容c50c4a23307529b59797525c52b2c50c * file1.zip将多个响应到一个响应
现在我想file1Response和file2Response &回报JSON组合文件。如何做到这一点的帮助?
@GET
@Path("/" + getfileschecksum)
@Produces("application/json")
public Response getFilesChecksum() {
String fileid1 = "file1";
String fileid2 = "file2";
Response file1Response = getChecksum(fileid1);
Response file2Response = getChecksum(fileid2);
return file1Response;
}
尝试添加一个ArrayList如下:
@GET
@Path("/" + getfileschecksum)
@Produces("application/json")
public Response getFilesChecksum() {
String fileid1 = "file1";
String fileid2 = "file2";
ArrayList<Response> rp = new ArrayList<Response>();
Response file1Response = getChecksum(fileid1);
Response file2Response = getChecksum(fileid2);
rp.add(file1Response);
rp.add(file2Response);
return Response.ok(rp).build();
}
被返回错误com.sun.jersey.api.MessageException:消息正文写入器,用于Java类的java.util.ArrayList和Java未找到类型类java.util.ArrayList和MIME媒体类型application/json。
file1Response来自下面,可以在下面改变任何东西来返回字符串。
URL url = new URL(binpath);
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
String mt = connection.getContentType();
ResponseBuilder response = Response.ok((Object) is, mt);
response.header("Content-Disposition","attachment; filename=" + binpath.substring(binpath.lastIndexOf('/') + 1, binpath.length()));
return response.build();
我假设Response是javax.ws.rs.core.Response对象。首先这是行不通的,因为它是一个接口,你必须添加@JsonTypeInfo来告诉序列化器如何序列化它。您需要将ArrayList转换为ArrayList,并将实际的字符串值放在那里,而不是Response对象。 –
我试过file1Response.getEntity()。toString(),但是这会返回[email protected]而不是实际的内容。如何从响应中获取字符串? – Newbie