Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use retrofit without model class?

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?

like image 203
Vadivel Avatar asked Nov 09 '16 09:11

Vadivel


People also ask

Is retrofit a REST client?

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.

What is retrofit model?

Retrofit is type-safe REST client for Android and Java which aims to make it easier to consume RESTful web services.

Is retrofit a framework?

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.


1 Answers

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) {

            }
        });
like image 199
chetan Avatar answered Sep 22 '22 06:09

chetan