0

I am new in android. I have bought one android application template from codecanyon. This app was using OKHTTP and JSON for get and send data. I have hire one freelancer for implement Retrofit+GSON for networking purpose because I have read that its give Good Performance. He have changed and used response like below

        public void onResponse(retrofit2.Call<JsonObject> call, retrofit2.Response<JsonObject> response) {
            try {
                final String myResponse = response.body().toString();
                Log.e("CheckDevice", "" + myResponse);

                JSONObject pJSONResponse = new JSONObject(myResponse);
                if (pJSONResponse.getInt("code") == 1) {
                    NumberData.getInstance().mNews = pJSONResponse.getString("news");
                    Log.e("News", NumberData.getInstance().mNews);
                    SharedPreferences.Editor editor = getSharedPreferences("setting", MODE_PRIVATE).edit();
                    editor.putInt("membership", pJSONResponse.getInt("membership"));
                    editor.apply();
                } else {
                    if (!SplashActivity.this.isFinishing()) {
                        AlertManager.createSingleCallbackAlert(mActivity, "Error", "Server Problem", false, "Retry", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                checkDevice(membership);
                            }
                        });
                    }
                }
            } catch (Exception e) {
                if (!SplashActivity.this.isFinishing()) {
                    AlertManager.createSingleCallbackAlert(mActivity, "Error Occurred", "Error while communicating with server", false, "Retry", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            checkDevice(membership);
                        }
                    });
                    Log.e("Error", "" + e.toString());
                }
            }
        }

I have told him to implement retrofit with proper way. I have marked that he have not used POJO and Instead used JsonObject directly in it. Can I know there any special benefit of using POJO or its OK to continue with above solution with JsonObject?

Thanks

Priti Patel
  • 21
  • 1
  • 6
  • you can see https://stackoverflow.com/questions/14172621/whats-the-advantage-of-pojo to get your answer ! – GianhTran Jul 12 '18 at 02:18
  • Making use of a POJO certainly has its advantages over using `JsonObject`. POJO classes can definitely save a lot of your time and effort especially when you have to reuse the same `object` elsewhere in your code. Having said that, `JsonObject` also has its advantages, suppose where you just need the response for the moment and don't really care about using it anywhere else(this is just an example scenario, POJOs and JsonObject has other advantages as well) – Navneet Krishna Jul 12 '18 at 07:27

0 Answers0