I want to retrieve a Json from server and pass it to WebView and consume it in a JavaScript function. So I think I dont need a Java class to hold the data and consume it in Java environment. Actually I want to omit the mediator calss (Users) I used in Retrofit. It was complicated for me to understand the structrure of retrofit request so I have no idea how to consume the response directly without a mediator class. This is my current code:
in Main Activity:
public void getUserList(){
GetUsers users = RetrofitInstance.getRetrofitInstance().create(GetUsers.class);
Call<Users> call = users.getUserList("myUsername");
call.enqueue(new Callback<Users>() {
@Override
public void onResponse(Call<Users> call, Response<Users> response) {
PassUsersToJavaScript(response.body().getList());
}
@Override
public void onFailure(Call<Users> call, Throwable t) {
Toast.makeText(MainActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
public void PassUsersToJavaScript(String users){
//Here I pass users to WebView
}
This is the mediator Users class that I want to omit:
public class Users {
@SerializedName("users")
private String users;
public Users(String users) {
this.users = users;
}
public String getList(){
return users;
}
}
and this is the mediator Interface GetUsers :
public interface GetUsers {
@GET("list/")
Call<Users> getUserList(@Query("user") String user);
}
How can I omit the class Users.java and use the response.body() driectly in the line below:
public void onResponse(Call<Users> call, Response<Users> response) {
PassUsersToJavaScript(response.body().getList());
}