Last active
August 29, 2015 14:04
-
-
Save Aracem/d3ef70a8ac2e618b5575 to your computer and use it in GitHub Desktop.
Android Studio TemplateTemplate to implement Gson serialization and deserialization in a bean
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
/** | |
* 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