Skip to content

Instantly share code, notes, and snippets.

@Aracem
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Aracem/d3ef70a8ac2e618b5575 to your computer and use it in GitHub Desktop.
Save Aracem/d3ef70a8ac2e618b5575 to your computer and use it in GitHub Desktop.
Android Studio TemplateTemplate to implement Gson serialization and deserialization in a bean
/**
* Template to implement Gson serialization and deserialization in a bean
*
* Declaration: Java - Declaration
* Variables:
* $TYPE$ expresion: className() defaultValue: Object
*
* Follow this instruction to add it to Android Studio
* http://dmytrodanylyk.com/pages/blog/templates.html
*/
@NotNull
public String toGson(){
Gson gson = new Gson();
return gson.toJson(this);
}
public static $TYPE$ fromJson(@NotNull String json){
Gson gson = new Gson();
return gson.fromJson(json, $TYPE$.class);
}
public static $TYPE$ fromJson(@NotNull JSONObject json){
return fromJson(json.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment