Skip to content

Instantly share code, notes, and snippets.

@MaySnow
Created October 6, 2012 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaySnow/3844409 to your computer and use it in GitHub Desktop.
Save MaySnow/3844409 to your computer and use it in GitHub Desktop.
Gson
public String showJson() throws IOException {
user = new User();
user.setId(1001);
user.setPassword("000000");
user.setUsername("tom");
response.setContentType("application/json;charset=UTF-8");
Gson gson = new Gson();
PrintWriter out = response.getWriter();
out.print(gson.toJson(user));
out.flush();
out.close();
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment