Last active
February 16, 2019 22:24
-
-
Save writtmeyer/b9b643f1b479f678c220 to your computer and use it in GitHub Desktop.
If you want to keep your domain objects free from GSON annotations, this is a possible way to do this.
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
Gson gson = new GsonBuilder() | |
.registerTypeAdapter(Date.class, new DateTypeAdapter()) | |
.setFieldNamingStrategy(new FieldNamingStrategy() { | |
@Override | |
public String translateName(Field f) { | |
if (f.getName().equals("stars")) { | |
return "stargazers_count"; | |
} else if (f.getName().equals("repositories")) { | |
return "items"; | |
} else { | |
return FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES.translateName(f); | |
} | |
} | |
}) | |
.create(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment