Cannot get the Response from the Retrofit showing the JsonSyntaxException. I am getting the perfect response in Logcat by HTTPLoggingInterceptor but unable to get the resonse on onSuccess() method in call.enque().
Here is my api.
{
"collection_listings": [
{
"collection_id": 57213780054,
"updated_at": "2018-04-30T02:12:55-04:00",
"body_html": "",
"default_product_image": null,
"handle": "men",
"image": {
"created_at": "2018-04-30T01:11:11-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/men.jpg?v=1525065071"
},
"title": "Men",
"sort_order": "best-selling",
"published_at": "2018-04-30T01:10:24-04:00"
},
{
"collection_id": 57213911126,
"updated_at": "2018-04-30T01:56:41-04:00",
"body_html": "",
"default_product_image": null,
"handle": "kids",
"image": {
"created_at": "2018-04-30T01:57:03-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/kid.jpg?v=1525067823"
},
"title": "Kids",
"sort_order": "best-selling",
"published_at": "2018-04-30T01:56:41-04:00"
},
{
"collection_id": 57213878358,
"updated_at": "2018-04-30T01:52:36-04:00",
"body_html": "",
"default_product_image": null,
"handle": "women",
"image": {
"created_at": "2018-04-30T01:53:01-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/women.jpg?v=1525067581"
},
"title": "Women",
"sort_order": "best-selling",
"published_at": "2018-04-30T01:52:36-04:00"
},
{
"collection_id": 57206145110,
"updated_at": "2018-04-28T08:22:10-04:00",
"body_html": "",
"default_product_image": null,
"handle": "test",
"image": null,
"title": "test",
"sort_order": "best-selling",
"published_at": "2018-04-28T08:22:10-04:00"
},
{
"collection_id": 57205882966,
"updated_at": "2018-04-28T07:56:28-04:00",
"body_html": "",
"default_product_image": null,
"handle": "bath-rugs",
"image": null,
"title": "Bath rugs",
"sort_order": "best-selling",
"published_at": "2018-04-28T07:56:28-04:00"
},
{
"collection_id": 57205850198,
"updated_at": "2018-04-28T07:55:36-04:00",
"body_html": "",
"default_product_image": null,
"handle": "bath-mats",
"image": null,
"title": "Bath mats",
"sort_order": "best-selling",
"published_at": "2018-04-28T07:55:36-04:00"
},
{
"collection_id": 57127534678,
"updated_at": "2018-04-28T05:51:00-04:00",
"body_html": "<h3>DISCOVER THE CLASSICS</h3>\r\n<p><i>An enduring classic for every bath, we continue to elevate our solid collections by crafting each towel using innovative techniques and the finest organic, Egyptian and Turkish cottons and cotton blends.</i></p>",
"default_product_image": null,
"handle": "bath-towels",
"image": {
"created_at": "2018-04-16T08:44:13-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/2-1_Solid-Towels_112017c_1.jpg?v=1523882653"
},
"title": "bath towels",
"sort_order": "best-selling",
"published_at": "2018-04-28T05:51:00-04:00"
},
{
"collection_id": 57127501910,
"updated_at": "2018-04-28T05:51:00-04:00",
"body_html": "<h3>STEP INTO COMFORT</h3>\r\n<p><i>Step into indulgence with our exquisite selection of bath rugs and bath mats. Expertly designed, each collection captures style ranging from the distinctly textured to the ultra-absorbent and supremely plush.</i></p>",
"default_product_image": null,
"handle": "bath-mats-and-bath-rugs",
"image": {
"created_at": "2018-04-16T08:41:52-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/bath-rugs_4.jpg?v=1523882512"
},
"title": "bath-mats and bath-rugs",
"sort_order": "best-selling",
"published_at": "2018-04-28T05:51:00-04:00"
},
{
"collection_id": 57127436374,
"updated_at": "2018-04-28T05:51:00-04:00",
"body_html": "",
"default_product_image": null,
"handle": "bath-accessories",
"image": {
"created_at": "2018-04-16T08:36:15-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/7_Accessories_112017c.jpg?v=1523882175"
},
"title": "BATH ACCESSORIES",
"sort_order": "best-selling",
"published_at": "2018-04-28T05:51:00-04:00"
},
{
"collection_id": 57127403606,
"updated_at": "2018-04-28T05:50:59-04:00",
"body_html": "",
"default_product_image": null,
"handle": "bath-robes",
"image": {
"created_at": "2018-04-16T08:34:39-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/4_bathrobes_112017c_1.jpg?v=1523882079"
},
"title": "bath robes",
"sort_order": "best-selling",
"published_at": "2018-04-28T05:50:59-04:00"
},
{
"collection_id": 57127338070,
"updated_at": "2018-04-28T05:50:59-04:00",
"body_html": "",
"default_product_image": null,
"handle": "all",
"image": {
"created_at": "2018-04-16T08:37:10-04:00",
"src": "https://cdn.shopify.com/s/files/1/2331/3377/collections/new-arrivals-042018.jpg?v=1523882230"
},
"title": "all products",
"sort_order": "best-selling",
"published_at": "2018-04-28T05:50:59-04:00"
}
]
}
APIClient.java
public class APIClient {
private static Retrofit retrofit = null;
private static final String BASE_URL = "https://ps-test.myshopify.com/admin/";
public static Retrofit getClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit;
}
}
ApiInterface.java
public interface ApiInterface {
@GET("collection_listings.json")
Call<Example> getCollectionList(@Header("Authorization") String accessToken);
}
Implementation in Activity:
private void fillListCategories() {
apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<Example> call = apiInterface.getCollectionList("Basic OWUzNmY1NWVlNGY1NTk0YWE4OTFkZjg4MTAyYzBhMjg6MWQ3MmM0YmIwMzBiZmNlOTM5OWRlYmM4NjM3ZWFlYjM=");
call.enqueue(new Callback<Example>() {
@Override
public void onResponse(Call<Example> call, Response<Example> response) {
if (response.isSuccessful()) {
Log.d("Collection List", "onResponse:" + response.body());
}
}
@Override
public void onFailure(Call<Example> call, Throwable t) {
Log.d("Issue", "onFailure:" + t.fillInStackTrace());
}
});
}
Thanks in advance.
Try to get collection_id as long var or string in your Example class. because you are getting collection_id as a int but it's out of int range.
Hope this will help you.