LoginSignup
33
28

More than 5 years have passed since last update.

Gsonでsnake_caseのjsonをcamelCaseのクラスで受け取る

Posted at
User.java
public class User {
    public int id;
    public int age;
    public String firstName;
    public String lastName;
}
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);
33
28
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
28