I'm consuming a REST API with RestTemplate
and it does not follow good practices, like using HTTP status codes, for example.
Response to success:
{
"435": {
"Codigo": "435",
"Tipo": "",
"Corretor": "62",
"Cliente": "48304",
"DataHora": "2016-04-27 14:18:24",
"DataHoraAtualizacao": "",
"Assunto": "Visita - Imóvel 2",
"Local": "",
"Texto": "",
"DataHoraInicio": "2016-04-28 12:00:00",
"DataHoraFinal": "2016-04-28 12:20:00",
"Particular": "Nao",
"Imovel": "2",
"DiaInteiro": "Nao",
"Tarefa": "Nao",
"Concluido": "Nao"
},
"687": {
"Codigo": "687",
"Tipo": "",
"Corretor": "20",
"Cliente": "33040",
"DataHora": "2016-07-18 17:09:28",
"DataHoraAtualizacao": "",
"Assunto": "Visita - Imóvel 2",
"Local": "",
"Texto": "teste",
"DataHoraInicio": "2016-07-28 08:00:00",
"DataHoraFinal": "2016-07-28 09:00:00",
"Particular": "Nao",
"Imovel": "2",
"DiaInteiro": "Nao",
"Tarefa": "Nao",
"Concluido": "Nao"
}}
So far you can see a Map structure, as follows:
Map<String, MeuObjeto> meusObjetos;
Class MeuObjeto
public class MeuObjeto {
@JsonProperty("Codigo")
private Integer codigo;
@JsonProperty("Tipo")
private String tipo;
@JsonProperty("Corretor")
private String corretor;
@JsonProperty("Cliente")
private String cliente;
@JsonProperty("DataHora")
private String dataHora;
@JsonProperty("DataHoraAtualizacao")
private String dataHoraAtualizacao;
@JsonProperty("Assunto")
private String assunto;
@JsonProperty("Local")
private String local;
@JsonProperty("Texto")
private String texto;
@JsonProperty("DataHoraInicio")
private String dataHoraInicio;
@JsonProperty("DataHoraFinal")
private String dataHoraFinal;
}
Response in case of error (without records):
{
"status": "200",
"message": "A pesquisa não retornou resultados."
}
How do I map the class to predict the two cases?