Is it possible to use retrofit without model class?

前端 未结 5 1157
时光说笑
时光说笑 2021-01-02 02:38

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?

5条回答
  •  [愿得一人]
    2021-01-02 02:50

    @Vadivel here it is the version of GET based on @chetan work:

    @GET("http://your.api.url")
    Call getGenericJSON();
    
    Call call = api.getGenericJSON();
    call.enqueue(new Callback() {
    
        @Override
        public void onResponse(Call call, Response response) {
            if (response.isSuccessful() && response.body() != null) {
                Log.d(TAG, response.body().toString());
            } else {
                Log.e(TAG, "Error in getGenericJson:" + response.code() + " " + response.message());
            }
        }
    
        @Override
        public void onFailure(Call call, Throwable t) {
            Log.e(TAG, "Response Error");
        }
    });
    

提交回复
热议问题