0

I am using retrofit 2.3.0 for network in Android app. I get response of say Person object I deserialize it using GsonConverter. But sometime server sends normal String rather than json object then I get JsonSyntaxException because deserialzer expects json object rather than String. String comes only when server times out so rather than getting exception I want to show "time out".

How to handle these situations when server returns plain string rather than Object with Retrofit?

Community
  • 1
  • 1
Sharad
  • 589
  • 5
  • 19

1 Answers1

1

Use a generic Object in response and after you get the response, check if that matches either String or JSON. This method should work well i suppose.

Check out these answer for more details :

https://stackoverflow.com/a/40131471/9809880

https://stackoverflow.com/a/35634754/9809880

https://stackoverflow.com/a/37663405/9809880

Ganesh K
  • 126
  • 14