Skip to content

Instantly share code, notes, and snippets.

@tmf16
Created February 20, 2014 01:52
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 tmf16/9105549 to your computer and use it in GitHub Desktop.
Save tmf16/9105549 to your computer and use it in GitHub Desktop.
Gsonでsnake_caseのjsonをcamelCaseのクラスで受け取る
String json = "{id:3, age:30, first_name: 'hoge', last_name: 'fuga'}";
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
User user = gson.fromJson(json, User.class);
public class User {
public int id;
public int age;
public String firstName;
public String lastName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment