I am trying to convert my JSONObject object into java objects but continuously getting null values only in my java object. Seeking your suggestions that how can i set my json values as java object so that i can save those java objects in my hibernate entities. It would be greate if you could tell me how to create my java POJO according to this json.
Below is my json :
{
"msg": "1 out of 1 Transactions Fetched Successfully",
"transaction_details": {
"148042": {
"firstname": "Navneet",
"transaction_amount": "11.00",
"amt": "11.00",
"Settled_At": "0000-00-00 00:00:00",
"addedon": "2018-09-26 20:36:25",
"mode": "CC",
"card_no": "512345XXXXXX2346",
"additional_charges": "0.00",
"error_Message": "NO ERROR",
"payment_source": "payu",
"bank_ref_num": "368960",
"bankcode": "CC",
"txnid": "148042",
"unmappedstatus": "captured",
"udf5": null,
"mihpayid": "40399371551645689",
"udf3": null,
"udf4": null,
"net_amount_debit": 11,
"udf1": null,
"card_type": "MAST",
"udf2": null,
"Merchant_UTR": null,
"field9": " Verification of Secure Hash Failed: E700 -- Approved -- Transaction Successful -- Unable to be determined--E000",
"error_code": "E000",
"disc": "0.00",
"productinfo": "Health",
"request_id": "",
"field2": "178707",
"PG_TYPE": "AXISPG",
"name_on_card": "Mukesh",
"status": "success"
}
},
"status": 1
}
Here is my java code to convert json String into java objects:
if(response.getStatusCode().toString().equalsIgnoreCase("200")){
String responseString = response.getBody();
JSONObject responseJson = new JSONObject(responseString);
output=new com.google.gson.Gson().toJson(responseJson);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
PayUTransactionMap payutxnmap=objectMapper.readValue(responseString, PayUTransactionMap.class);
PayUTransactionMap obj = new Gson().fromJson(output, PayUTransactionMap.class);
transaction.setPgBankRefNo(payutxnmap.getBank_ref_num());
transaction.setPgTxnRefNo(payutxnmap.getMihpayid());
transaction.setPgTxnNo(payutxnmap.getBank_ref_num());
transaction.setTxnMode(payutxnmap.getBankcode());