mercredi 14 juillet 2021

Unknown property 'DEFAULTCAPACITY_EMPTY_ELEMENTDATA' when using reflection

I have a scenario where when I get a single result the data comes back well, but when the query finds multiple results, I get multiple errors that I don't understand. I am looping through the items to pick each items and add them to item details, but item details come back empty.

Here is my implementation

  public ArrayList<Summary> getHouseHoldRecordsByCase(String case) {
        ArrayList<HouseholdSummaryZampia> documents = new ArrayList<>();
        Summary summary = new Summary();
        ArrayList<ItemDetails> details = new ArrayList<>();
        List<HSEC01X> members = reportService.getHouseHoldMembersByCas(case);
        for (HSEC01X _m : members) {
            summary.recordType = "Members list";
            summary.case = case;
            details = new ArrayList<>();
            Field[] fields = members.getClass().getDeclaredFields();
            for (Field _f : fields) {
                try {
                    String val = PropertyUtils.getProperty(_m, _f.getName()).toString();
                    details.add(new ItemDetails(val, _f.getName(), val, _f.getName()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            summary.itemDetails = details;
            documents.add(summary);
        }
        return documents;
    }

this is the JSON am getting back, with empty itemDetails, but there are 9 members found, but there details are not being populated on the itemDetails.

[
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  },
  {
    "case": "01840005",
    "recordType": "Members list",
    "itemDetails": []
  }
]

This is an example of how I want the JSON returned

[
    {
        "case": "01840005",
        "recordType": "Members list",
        "itemDetails": [
            {
                "ItemValue": "023",
                "Label": "Area Code",
                "ItemValueLabel": "023",
                "Name": "hA"
            },
            {
                "ItemValue": "0005",
                "Label": "Manager Identification",
                "ItemValueLabel": "0005",
                "Name": "hUM"
            },
            {
                "ItemValue": "5",
                "Label": "County Name",
                "ItemValueLabel": "5",
                "Name": "hCounty"
            }
        ]
    },
    {
        "case": "01840005",
        "recordType": "Members list",
        "itemDetails": [
            {
                "ItemValue": "023",
                "Label": "Area Code",
                "ItemValueLabel": "023",
                "Name": "hA"
            },
            {
                "ItemValue": "0005",
                "Label": "Manager Identification",
                "ItemValueLabel": "0005",
                "Name": "hUM"
            },
            {
                "ItemValue": "0005",
                "Label": "House Code",
                "ItemValueLabel": "0005",
                "Name": "hPUM"
            }
         
        ]
    }

How can I return each individual member record on his own itemdetails and not have empty itemdetails?





Aucun commentaire:

Enregistrer un commentaire