Я использую приведенный ниже код для пересылки запроса на другой сервер, затем я хочу преобразовать ответ в определенный класс в формате JSON, но я получил ответ, com.mydomain.models.Result@f87ad6
, что мне делать дальше?
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
final HttpServletResponse response = (HttpServletResponse) res;
conn = (HttpURLConnection) url.openConnection();
...
Boolean isGzip = "gzip".equals(conn.getContentEncoding());
InputStream in = conn.getInputStream();
if (isGzip) {
in = new GZIPInputStream(in);
}
JSONObject resData = (JSONObject) new JSONParser().parse(new InputStreamReader(in, "UTF-8"));
Result<String> result = new Result<String>();
result.setData(resData.toJSONString());
pipe(new ByteArrayInputStream(result.toString().getBytes("UTF-8")), response.getOutputStream());
...
}
private void pipe(InputStream in, OutputStream out) {
int b = -1;
try {
while ((b = in.read()) > -1) {
out.write(b);
}
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
...
public class Result<T> {
priavte String status;
private T data;
...
}