Reputation: 2818
I have to handle an API that response with [] if there is no value to return. How to get this response in retrofit onResponse? Currently, it return an error in onFailure of retrofit
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
Maybe I could do something like checking if (response.body() == null) in onResponse once onResponse is called.
Upvotes: 0
Views: 705
Reputation: 372
While write JSON responce in service (it may be in .net or .php) you need to write this responce in terms of object like "{}". If you want to get responce in array then write in [] and for object write in {}.
Upvotes: 0
Reputation: 718
You should get response like this
ArrayList<ResponseClass> responseList= response.body();
if(responseList.size() > 0) {
} else {
}
Upvotes: 0