I'm using Woo-Commerce RestApi v2, using Retrofit
for api calling. when I'm fetching all category. There was a node name image
, it returns blank array but when image uploaded it returns object. Here is my JSON sample
[
{
"id": 15,
"name": "Albums",
"slug": "albums",
"parent": 11,
"description": "",
"display": "default",
"image": [],
"menu_order": 0,
"count": 4
},
{
"id": 9,
"name": "Clothing",
"slug": "clothing",
"parent": 0,
"description": "",
"display": "default",
"image": {
"id": 730,
"date_created": "2017-03-23T00:01:07",
"date_created_gmt": "2017-03-23T03:01:07",
"date_modified": "2017-03-23T00:01:07",
"date_modified_gmt": "2017-03-23T03:01:07",
"src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg",
"title": "",
"alt": ""
},
"menu_order": 0,
"count": 36
}
]
The main problem with image node.
How to create model class for that node. I used jsonschema2pojo.org for generate model class but that class only works, When I remove image
from class.
can you guide me what to do?
Any help would be appreciated.
ApiInterface apiService= ApiClient.getWooCommerceClient().create(ApiInterface.class);
Call<List<Category>> call=apiService.getAllCategories();
call.enqueue(new Callback<List<Category>>() {
@Override
public void onResponse(@NonNull Call<List<Category>> call, @NonNull Response<List<Category>> response) {
categoryList.addAll(response.body());
adapter.notifyDataSetChanged();
}
@Override
public void onFailure(@NonNull Call<List<Category>> call, @NonNull Throwable t) {
}
});