Right now in my Android Development journey Google GSON becomes my favorite arsenal
for converting JSON to Java objects vice versa.
Benefits using GSON:
1. Its very handy to use.
2. The number of codes will be lessen.
3. Once you converted Java objects to JSON you can now pass it thru intent bundle as a String.
Heres a step by step sample How GSON can help you to parse JSON objects
To Java Pojo.
GSON PART:
1.) Create a directory under main folder name it “assets”
src > main > assets
2.) Create a File “androidwear.json”
src > main > assets > androidwear.json
3.) Create class name “BaseWatch.java”
src > main > java > {package name} > BaseWatch.java
Basically this BaseWatch will serve as JSON parser that uses Google GSON library.
4.) Create Class name “Watch.java”
src > main > java > {package name} > Watch.java
This class also serve as JSON parser it will get the inner data of androidwear.json
VIEW PART:
5.) After doing the 4 steps above we need to create two layouts for the Activity and Adapter;
5.1) Create a xml file “activity_main.xml”
res > layout > activity main.xml
this will serves as the main display container of the app.
5.2) Create a xml file “list_item_watch.xml”
res > layout > list_item_watch.xml
this will be the view for the list item.
6.) Once you already finished creating the two layouts, the next step will be create the “MainActivity.java”.
src > main > java > {package name } > MainActivity.java
7.) After that, Create a class “WatchAdapter.java” this class will be the incharge of inflating the data to ListItem.
src > main > java > {package name } > WatchAdapter.java
Note: If you are still not knowledgable with BaseAdapter you can visit this first
readme
8.) Heres my default Build Gradle Dependencies together with Google GSON
SCREENSHOT


D
ownload Source Code via Github