I'm really slow and I can't grasp how I can initialize that I am going into object then into an array.
I've tried making a new Gson from the Components, but I don't know how.
Should I make a new Class inside of the model, thats also an Array? And then do <ArrayList<Component.Components(inside class)>>
?
Model
public class Component {
@SerializedName("total")
transient private Integer total;
@SerializedName("rows")
private ArrayList<Rows> rows;
public class Rows {
@SerializedName("name")
private String name;
@SerializedName("image")
private String image;
@SerializedName("serial")
private String serial;
@SerializedName("purchase_cost")
private String cost;
public Rows(String name, String image, String serial, String cost) {
this.name = name;
this.image = image;
this.serial = serial;
this.cost = cost;
}
//getters
}
}
API
@GET("api/v1/components")
Call<ArrayList<Component.Rows>> listComponents();
MainActivity
JsonPlaceHolderApi jsonPlaceHolderApi = ApiClient.getClient().create(JsonPlaceHolderApi.class);
Call<ArrayList<Component.Rows>> call = jsonPlaceHolderApi.listComponents();
call.enqueue(new Callback<ArrayList<Component.Rows>>() {
@Override
public void onResponse(@NonNull Call<ArrayList<Component.Rows>> call, @NonNull Response<ArrayList<Component.Rows>> response) {
ArrayList<Component.Rows> posts = response.body();
componentAdapter = new ComponentAdapter(getApplicationContext(),posts);
listView.setAdapter(componentAdapter);
}
JSON:
{
"total": 1,
"rows": [
{
"id": 1,
"name": "HP ENVY x360 - 13-ag0017nn - 4UE32EA AMD® Raven Ridge Ryzen 7 2700U do 3.8GHz, 13.3", 512GB SSD, 8GB",
"image": "http://server/uploads/components/7cDXBttwk2O5p5sEM5T9raBvW.png",
"serial": "193015227095",
"location": {
"id": 1,
"name": "ICB"
},
This is the response json.