android - How to handle response which can be different Type in Retrofit 2 -


in webapi returned json's field can of different class:

{ somefield:"some string" } { somefield: { "en" : "some string", "ka" : "რამე სტრინგი" } } 

i've seen solutions, on previous versions of retrofit.

how pojo class , can use parse dynamic json?

for case can use call<jsonelement> response type , parse in response:

call.enqueue(new callback<jsonelement>() {         @override         public void onresponse(call<jsonelement> call, response<jsonelement> response) {             if(response.issuccessful()){                 jsonelement jsonelement = response.body();                 if(jsonelement.isjsonobject()){                     jsonobject objectwhichyouneed = jsonelement.getasjsonobject();                 }                  // or can use jsonelement.getasjsonarray() method                 //use json deserializer convert class.             }             else{                 system.out.println(response.message());             }         }         @override         public void onfailure(call<jsonelement> call, throwable t) {             system.out.println("failed");         }     }); 

Comments