Copy/paste this JSON as input of this page http://www.jsonschema2pojo.org/:
[
{
"id": 1,
"name": "ANDY",
"Game": {
"car": "1 Item",
"plane": "1 Item"
},
"location": {
"home": 5.555,
"office": 150.316
}
}
]
You had a }
instead of a ]
to close it up, on biggies. Now change the source type to JSON and select your converter accordingly.
You can check the Retrofit's available converters in their main documentation almost at the bottom of the page http://square.github.io/retrofit/.
Make sure you add the needed line to your gradle, being that something similar to:
Gson: com.squareup.retrofit2:converter-gson
Jackson: com.squareup.retrofit2:converter-jackson
Moshi: com.squareup.retrofit2:converter-moshi
Protobuf: com.squareup.retrofit2:converter-protobuf
Wire: com.squareup.retrofit2:converter-wire
Now from jsonschema2pojo click on "Preview" or "Zip" you will then be able to download your new model. Copy those classes to your project.
Your new Retrofit interface will look something like:
public interface YourService {
@GET("your/url")
Call<Yourclass> listStuff();
}
Then, after that, you will be able to make the HTTP request with:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create()) //Converter
.build();
// Create an instance of our GitHub API interface.
YourService service = retrofit.create(YourService.class);
// Create a call instance for looking up Retrofit contributors.
Call<Yourclass> call = service.listStuff();
And get your games and locations with:
Yourclass myclass = call.execute().body();
Game game = myclass.getGame();
Location location = myclass.getLocation();
Check these if you want to get more details:
https://github.com/square/retrofit/blob/master/samples/src/main/java/com/example/retrofit/SimpleService.java
http://square.github.io/retrofit/
https://github.com/joelittlejohn/jsonschema2pojo