Answer the question
In order to leave comments, you need to log in
Retrofit: what to do when the structure of the server response changes?
Hey!
I understand with API, the detailed description to which is not present.
For example, a GET request to the server: _https:_//server.net/getdetails/?ctn=4950000001
If everything is OK, a response with a 200 code will be returned:
{"code": "495", "num": "0000001", "full_num": "4950000001", "operator": "МГТС", "region": "г. Москва"}
{"code": "900", "num": "5555555", "full_num": "9005555555", "operator": "ВымпелКом", "old_operator": "СИМ ТЕЛЕКОМ", "region": "г. Москва * Московская область"}
, the old_operator parameter is added . {"info": "Неверный формат номера: 49500000", "example": ["+74959898533", "74959898533", "84959898533", "4959898533"]}
{"info": "Номер не найден. Проверьте код города: 000", "example": ["3XX", "4XX", "8XX", "9XX"]}
{"info": "Неверный формат запроса, ctn обязательный параметр", "example": "https://server.net/getdetails/?ctn=+74959898533"}
Answer the question
In order to leave comments, you need to log in
Yes, you can live with it. Retrofit itself does not convert the response to json, for this it is given addConverterFactory(factory). You need to write a custom adapter for the json conversion library that you use (examples about Gson ). From the response, you will have to understand what exactly came and return the corresponding object.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question