I'm using Retrofit
with POJO
, which usually works, but the answer has two different objects depending on whether the result is valid. Which one is a String
and the another is an Object
:
{
"data":"No results."
}
or:
{
"data": {
"exame": [
{
"id": 776,
"codigo": "DHT",
"instrucao": "- Text."
},
{
"id": 776,
"codigo": "DHT",
"instrucao": "- Text"
}
]
}
}
And my class:
public class Exame {
@SerializedName("data")
@Expose
@Nullable
private ExameItem exameItem;
private String mensagem;
public ExameItem getExameItem() {
return exameItem;
}
public void setExameItem(ExameItem exameItem) {
this.exameItem = exameItem;
}
public String getMensagem() {
return mensagem;
}
public void setMensagem(String mensagem) {
this.mensagem = mensagem;
}
}
When I do Exame().getExameItem
its fine, but when I try test if have a message in Exame().getMessagem
its bring me a this error:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 10 path $.data
So, I think how can I test if @data is a String
of an Object
, but I don't kwon how, anyone may help?