public static void writeJson(HttpServletResponse response,Object obj){
response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
try {
PrintWriter writer = response.getWriter();
writer.print(Json.toJson(obj, JsonFormat.compact()));
} catch (IOException e) {
e.printStackTrace();
}
response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
try {
PrintWriter writer = response.getWriter();
writer.print(Json.toJson(obj, JsonFormat.compact()));
} catch (IOException e) {
e.printStackTrace();
}
}