0

Below is the example of JSON object.

{  
   "primaryAccountNumber":"4353453",
   "processingCode":"3453",
   "transactionAmount":"34534",
   "transmissionDateTime":"34534",
   "receiptsFields":{  
      "line":"BHN VALIDATION - DAR",
      "line":"Phone",
      "line":":Amount: 25.00",
      "line":"BHN Order ID: 9GMAQH0",
      "line":"ALL SALES FINAL",
      "line":"Terms and Conditions",
      "line":"Store ID: 06220",
      "line":"redemptionAccountNumber",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":":"
   },
   "termsAndConditions":"Terms and Conditions of the card will be displayed in this area. The maximum characters allowed are nine hundred and ninety nine (999)."
}

What will be the type of receiptsFields to map in POJO ? For example transmissionDateTime we have String. Same suggest me type for receiptsFields so that response will map into pojo automatically.

Thomas Martin
  • 678
  • 8
  • 19

1 Answers1

-1

The name of your type does not matter, as long as it has the right properties in it. In your case something like

public class ReceiptField{
    public String line;
}

However, I don't think this JSON does what you want to achieve. In your receiptsFields property, all properties are named line, so only the last one will be taken into account (being ":" in your example). An array seems a better fit here.

EDIT : To answer your comment, do you have control on the input JSON ? If so it would be :

 {
  "primaryAccountNumber": "4353453",
  "processingCode": "3453",
  "transactionAmount": "34534",
  "transmissionDateTime": "34534",
  "receiptsFields": [
    "BHN VALIDATION - DAR",
    "Phone",
    ":Amount: 25.00",
    "BHN Order ID: 9GMAQH0",
    "ALL SALES FINAL",
    "Terms and Conditions",
    "Store ID: 06220",
    "redemptionAccountNumber",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ":"
  ],
  "termsAndConditions": "Terms and Conditions of the card will be displayed in this area. The maximum characters allowed are nine hundred and ninety nine (999)."
}
Thomas Martin
  • 678
  • 8
  • 19
  • you are right. For Now I am getting ":" only. Can you please give me example for Array ? like how we can handle – Gaurav Khandelwal Aug 21 '19 at 11:53
  • See my edit, it supposes to change the JSON input though. – Thomas Martin Aug 21 '19 at 12:01
  • No I dont have Control over Input Json. Input JSON will be same like that. We cant change input String. – Gaurav Khandelwal Aug 21 '19 at 12:09
  • 1
    Then if you need all information in receiptFields, I'm afraid you have no other choice than parsing it manually, because as @Jaboy mentionned, non unique property names aren't suppose to occur. My advice is to do string manipulation to transform input JSON into what I suggested, then parse it into an object. – Thomas Martin Aug 21 '19 at 12:15