Can response and request data types be different?

Home / Uncategorized / Can response and request data types be different?

Question:
I mean to say that call and response have different data types I send JSON and get string in response in retrofit2
Call call = client.createUser(user);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
kik=response.body().getId();
Log.d("fhjhh", ""+response.body().);
}

@Override
public void onFailure(Call call, Throwable t) {
String message = t.getMessage();
Log.d("failure", message);
}
});


Answer:
Try this,
Call call = client.createUser(user);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
User user = (User) response.body();
Log.d(">>Response",user.toString());
}

@Override
public void onFailure(Call call, Throwable t) {
String message = t.getMessage();
Log.d("failure", message);
}
});

Create toString() method in your model class called User.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *