我有低於此下載與內容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