i have problem to use model class in retrofit lib. A backend side field name has changed.
Is it possible to get response without model class?
Retrofit is a REST Client for Java and Android allowing to retrieve and upload JSON (or other structured data) via a REST based You can configure which converters are used for the data serialization, example GSON for JSON.
Retrofit is type-safe REST client for Android and Java which aims to make it easier to consume RESTful web services.
Retrofit is a type-safe REST client for Android, Java and Kotlin developed by Square. The library provides a powerful framework for authenticating and interacting with APIs and sending network requests with OkHttp.
Yes, you can.
@POST("url")
Call<JsonObject> register(@Query("name") String name,
@Query("password") String password);
Just write JsonArray or JsonObject according to your response instead of Model class.
Then, get data from JsonObject or JsonArray which you get in response as below
Call<JsonObject> call = application.getServiceLink().register();
call.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
JsonObject object = response.body();
//parse object
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t) {
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With