Created
February 20, 2014 01:52
-
-
Save tmf16/9105549 to your computer and use it in GitHub Desktop.
Gsonでsnake_caseのjsonをcamelCaseのクラスで受け取る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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