0

I have a ResponseEntity which contains json string. I need to read values from that string and remove the duplicated objects.

Json String :

{
    "AccountList": {
        "Accounts": [
            {
                "Id": 1466010,
                "IdSpecified": true,
                "Number": "04F200S",
                "ClientId": 82694,
                "ClientIdSpecified": true,
                "ClientNumber": "04F200",
                "Name": "name 04F200S",
                "RepresentativeId": "RM00",
                "Currency": "CAD",
                "Balance": 169.03,
                "BalanceSpecified": true,
                "TotalValue": 169.03,
                "TotalValueSpecified": true,
                "MarketValueSpecified": false,
                "Type": "S",
                "AccountTypeFr": "REER autogéré",
                "AccountTypeEn": "Self Directed RRSP",
                "InceptionDate": "2013-06-10T00:00:00-04:00",
                "InceptionDateSpecified": true,
                "ClassType": "ACCOUNT",
                "ClassDescription": "Real Account",
                "StatusSpecified": false,
                "CurrencyPerformanceListSpecified": false,
                "PerformancePeriodListSpecified": false,
                "AssetAllocationSpecified": false,
                "SecurityListSpecified": false
            }
        ]
    },
    "CurrencyPerformanceList": {
        "CurrencyPerformances": [
            {
                "Currency": "CAD",
                "PerformanceList": {
                    "PerformanceTypeSpecified": false,
                    "KeySpecified": false,
                    "KeyIdSpecified": false,
                    "Performances": [
                        {
                            "StartDate": "2014-01-15T00:00:00",
                            "StartDateSpecified": true,
                            "EndDate": "2014-06-01T00:00:00",
                            "EndDateSpecified": true,
                            "Currency": "CAD",
                            "ROI": 5.503494,
                            "ROISpecified": true,
                            "NonAnnualizedROI": 5.503494,
                            "NonAnnualizedROISpecified": true,
                            "StartingValue": 97878.26,
                            "StartingValueSpecified": true,
                            "EndingValue": 103337.68,
                            "EndingValueSpecified": true,
                            "Inflows": 70.5,
                            "InflowsSpecified": true,
                            "Outflows": 0,
                            "OutflowsSpecified": true,
                            "Revenues": 1667.19999936,
                            "RevenuesSpecified": true,
                            "StandardDeviationSpecified": false,
                            "NonAnnualizedStandardDeviationSpecified": false,
                            "SharpeIndexSpecified": false,
                            "NonAnnualizedSharpeIndexSpecified": false
                        }
                    ],
                    "PerformancesSpecified": true
                }
            }
        ]
    }
}

What I am trying to do :

performance = objectMapper
                            .readValue(performanceQueryService.getAggregatedAccountPerformances(req).getBody(), PeriodData.class)
                            .getCurrencyPerformanceList();

Perioddata. Class :

public class PeriodData {

    private List<String> accountList;
    private CurrencyPerformances CurrencyPerformanceList;

    public List<String> getAccountList() {
        return accountList;
    }
    public void setAccountList(List<String> accountList) {
        this.accountList = accountList;
    }
    public CurrencyPerformances getCurrencyPerformanceList() {
        return CurrencyPerformanceList;
    }
    public void setCurrencyPerformanceList(CurrencyPerformances currencyPerformanceList) {
        CurrencyPerformanceList = currencyPerformanceList;
    }

}

Please let me know where I am doing wrong while reading the value. It just sets null to the variable performance. Thanks!

Anuja Patil
  • 47
  • 1
  • 10
  • Can you just copy the objects into a HashSet? – JustinKSU Jan 09 '19 at 15:02
  • 1
    Where in your code are you attempting to remove dublicates? – T A Jan 09 '19 at 15:02
  • For the "Performance" we receive duplicated objects. I haven't posted it here. – Anuja Patil Jan 09 '19 at 15:03
  • also, there are multiple responses just like that json string. I need to merge all the responses into single "Performances" tag. – Anuja Patil Jan 09 '19 at 15:04
  • So what have you tried so far to merge these responses? If thats your actual question, you should take a look at [this answer](https://stackoverflow.com/questions/39945039/java-merge-json-files) and try to solve it yourself first. – T A Jan 09 '19 at 15:06
  • JSONObject object = (JSONObject) JSONValue.parse(res.getBody()); Object currPerfList = object.get("Performances"); I am trying to do this, but it doesnt seem to read Performaces but it reads CurrencyPerformanceList. – Anuja Patil Jan 09 '19 at 15:17

0 Answers0