Skip to content

Instantly share code, notes, and snippets.

@datienza
Forked from Aracem/GsonTemplate.java
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save datienza/7a09177607d35aa0705e to your computer and use it in GitHub Desktop.

Select an option

Save datienza/7a09177607d35aa0705e to your computer and use it in GitHub Desktop.
/**
* 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