I am using retrofit 2 and i have have api where if user detail available then it will return user detail object or else i will send a message saying user detail not found.
Call<ResponseBody> getCustomerDetail(@Path(value="userDetailId", encoded=true) String userDetailId);
if i have above call as ResponseBody
then if i convert to string then i get string json response.
Log.d("detail",response.body().string());
My question is how i can convert response to My UserDetail pojo class
?
if i add Call<UserDetail>
then i cant check if user detail not found.so is there any way to achieve this
I have tried below method but not working
JSONObject obj = new JSONObject(response.body().string());
Log.d("userdetail",obj.toString());
another method
Gson gson = new GsonBuilder().create();
UserDetail userDetail=gson.fromJson(obj.toString(),UserDetail.class );
Three scenarios of response
{
"customer_id": 138,
"customer_name": "John",
"customer_address": "Usa",
"customer_primary_mobile": "2353253232325",
"customer_secondary_mobile": "325322353232",
"customer_location": null,
"customer_type_id": 14
}
second
{
"message": "No Records Found"
}
third
{
"message": "Some think went wrong"
}