Showing results for 
Search instead for 
Did you mean: 

Body annotation sends only the object reference

Posted on

I am using paypal gateway in android, and i am using retrofit library to post the order request, but when i use body annotation to send the body data (intent and purchase_units) i get the object reference when i log my request here is the code i am using



@SerializedName("intent") private String intent; @SerializedName("purchase_units") private JSONArray purchase_units; public String getIntent() { return intent; } public void setIntent(String intent) { this.intent = intent; } public JSONArray getPurchase_units() { return purchase_units; } public void setPurchase_units(JSONArray purchase_units) { this.purchase_units = purchase_units; }


Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder().baseUrl("") .addConverterFactory(GsonConverterFactory.create(gson)).build(); orderRequest Order = retrofit.create(orderRequest.class); orderBody orderBody = new orderBody(); JSONObject amountObj = new JSONObject(); JSONObject amount = new JSONObject(); try { amountObj.put("value","100"); amountObj.put("currency_code","USD"); amount.put("amount",amountObj); } catch (JSONException e) { e.printStackTrace(); } JSONArray Purchase = new JSONArray(); Purchase.put(amount); orderBody.setIntent("CAPTURE"); orderBody.setPurchase_units(Purchase); Call<String> call = Order.Order("application/json","Bearer A21AALZqJhprXJGWTCFeBR_EPIx6CnkPSNtLpeSy5yhY3_eDU3wQ8_n4KjaVzounHcDf_nOzCaq63Kje5_nsp5xWiGK53amGA",orderBody); call.enqueue(this); } @Override public void onResponse(Call<String> call, Response<String> response) { try { Log.d("RESPONEPYPAL",call.request().toString()+response.errorBody().string()); } catch (IOException e) { e.printStackTrace(); } } @Override public void onFailure(Call<String> call, Throwable t) { }

 and here is the request and respond logs


        Request{method=POST, url=, tags={class retrofit2.Invocation=c.shobaky.tofahaway.orderRequest.Order() [application/json, Bearer A21AALZqJhprXJGWTCFeBR_EPIx6CnkPSNtLpeSy5yhY3_eDU3wQ8_n4KjaVzounHcDf_nOzCaq63Kje5_nsp5xWiGK53amGA, c.shobaky.tofahaway.orderBody@c6bb624]}}


"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"9a99b6bbf4f0","details":[{"field":"/purchase_units","location":"body","issue":"INVALID_SYNTAX","description":"MALFORMED_REQUEST_JSON"}],"links":[{"href":"","rel":"information_link","enc..."}]


i also used the Field annotation but i am getting also MALFORMED_REQUEST



Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.