title: How to externalise volley json parsing to a separate class file so the code will be loosely coupled?
body: <p>I have got a class called Client.class. Within this, I have got a method as follows where Im invoking a volley to fire api requests.</p>
  
  <pre><code> public void dispatchLoginRequest() {
  
          //        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
  
          //        Log.d(TAG, "ADS " + frameLoginJson().toString());
          pDialog.setMessage("Logging in ...");
          showDialog();
  
          JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, "http://52.11.242.90:8082/api/login", frameLoginJson(), new Response.Listener&lt;JSONArray&gt;() {
  
              @Override
              public void onResponse(JSONArray response) {
                  parseLoginResponse(response);
  //                aparjithaDb.parseLoginResponse(response, this);
                  Parser.getInstance().parseLoginResponse(response,this,getApplicationContext());
                  pDialog.hide();
  
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
  
                  Log.d(TAG, "log" + frameLoginJson().toString());
                  error.printStackTrace();
                  pDialog.hide();
                  Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
              }
          });
  
          AppController.getInstance().getRequestQueue().add(jsonArrayRequest);
  
      }
  </code></pre>
  
  <p>I have the following method in other class called as Parse.class where im parsing the response and adding it to db.</p>
  
  <pre><code>public void parseLoginResponse(JSONArray response, ClientLogin clientLogin, ContextWrapper contextWrapper) {
          for (int i = 0; i &lt; response.length(); i++) {
              try {
  
                  JSONObject value = response.getJSONObject(i);
                  JSONArray configuration = value.getJSONArray("configuration");
                  int group_id = value.getInt("group_id");
                  String group_name = value.getString("group_name");
                  JSONObject menu = value.getJSONObject("menu");
                  JSONObject menus = menu.getJSONObject("menus");
                  JSONArray master = menus.getJSONArray("Master");
                  JSONArray transaction = menus.getJSONArray("Transaction");
                  JSONArray report = menus.getJSONArray("Report");
  
                  boolean approvalExists = isApprovalExists(transaction, "Compliance Approval");
                  boolean taskExists = isTaskExists(transaction, "Compliance Task Details");
  
                  Toast.makeText(contextWrapper.getApplicationContext(), "COOL" + approvalExists, Toast.LENGTH_SHORT).show();
                  for (int j = 0; j &lt; configuration.length(); j++) {
                      JSONObject jsonobject = configuration.getJSONObject(i);
                      int period_from = jsonobject.getInt("period_from");
                      int period_to = jsonobject.getInt("period_to");
                      int country_id = jsonobject.getInt("country_id");
                      int domain_id = jsonobject.getInt("domain_id");
  
                      Db.getInstance(contextWrapper).addClientConfig(new ClientConfig(j, String.valueOf(period_from), String.valueOf(country_id), String.valueOf(period_to), String.valueOf(domain_id), group_name, String.valueOf(group_id)));
                  }
                  Intent intent = new Intent(clientLogin, Client.class);
                  intent.putExtra("approvalExists", "" + approvalExists);
                  intent.putExtra("taskExists", "" + taskExists);
                  clientLogin.startActivity(intent);
  
                  // logClientDb();
  
  
              } catch (Exception e) {
                  Toast.makeText(contextWrapper.getApplicationContext(), "Please Check your user credentials..." + e.toString(), Toast.LENGTH_SHORT).show();
                  e.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>The problem is that im getting the following error</p>
  
  <p><code>Error:(91, 37) error: method parseLoginResponse in class Parser cannot be applied to given types;
  required: JSONArray,ClientLogin,ContextWrapper
  found: JSONArray,&lt;anonymous Listener&lt;JSONArray&gt;&gt;,Context
  reason: actual argument &lt;anonymous Listener&lt;JSONArray&gt;&gt; cannot be converted to ClientLogin by method invocation conversion</code></p>
  
  <p>Im just trying to externalise the way that Im parsing the json and adding it to db while using volley. How can I do so? </p>