0

I am trying to deserialize a rest service response which is something like this

Class ResponsePayload {

String status;
String errorDescription;

List<Object> responseDetails;

...
}

ResponsePayload gets parsed and under responseDetails I have a linked hashmap of the object which was sent.

On ResponsePayload, I have to again parse the object out of responseDetails.

I know beforehand the type of object which is going to be present in List.

What is the efficient and convenient way of doing this parsing in one go?

Is there a way to setup a deserializer to parse List into a type object.

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
Adilmo
  • 117
  • 1
  • 9
  • Did you ask about this? http://stackoverflow.com/a/5554296/1159507 – anber Dec 09 '16 at 06:45
  • my question is a bit different ... I know I can deserialize after getting the original object (ResponseDetails) ... However i would like to know if there is a way to setup my gsonfactory such that retrofit2 automatically returns this type object – Adilmo Dec 09 '16 at 06:51

1 Answers1

1

Retrofit automatically deserialize response to Your object type.what you have to do is jut specify the object type in response class like below

Class ResponsePayload {

String status;
String errorDescription;

List<ResponseDetails> responseDetails;

...
}
Rajesh.k
  • 2,327
  • 1
  • 16
  • 19