Starcounter-Jack / JSON-Patch

Lean and mean Javascript implementation of the JSON-Patch standard (RFC 6902). Update JSON documents using delta patches.
MIT License
1.79k stars 215 forks source link

Add operation on childs child node #231

Open shubhamshinde7 opened 5 years ago

shubhamshinde7 commented 5 years ago

Project configuaration Spring boot:2.1.4 json-patch:1.9 I have below json object: { "createdBy": "BKADMIN", "creationDttm": "2019-07-22T09:56:23.000+0000", "modifiedBy": "BKADMIN", "modifiedDttm": "2019-07-24T11:12:52.000+0000", "startDt": "2019-04-15", "endDt": "2020-03-02", "partyId": "8a80cb816c191744016c191c59bf0001", "pricelistId": "8a80cb816c191744016c191c640a0002", "priority": 1, "noOfTiers": null, "priceListName": null, "priceListShortName": null, "priceListDescription": null, "priceListTypeCd": null, "currencyCd": null, "altCurrencyCd": null, "altCurrencySw": null, "pricelistOwnerParty": null, "partyHierarchy": null, "inputPartyId": null, "partyPriceListExtensionList": [], "tierList": [ { "createdBy": "RK", "creationDttm": "2019-07-22T09:56:23.000+0000", "modifiedBy": "RK", "modifiedDttm": "2019-07-24T11:12:52.000+0000", "startDt": "2019-02-07", "endDt": null, "uom": null, "dfltCurcy": "GBP", "description": "Tier number 1", "parentId": "8a80cb816c191744016c191c6d600003", "partySpecificSw": "YES", "unitTypeCd": "VOLUME", "monthsToInclude": 1, "currMonthSw": "NO", "tierLines": [], "tierId": "8a80cb816c191744016c191c6d610004", "version": 7 } ], "id": "8a80cb816c191744016c191c6d600003", "version": 7, "_links": { "self": { "href": "http://localhost:9090/partypricelists/8a80cb816c191744016c191c6d600003" }, "partypricelists": { "href": "http://localhost:9090/partypricelists/8a80cb816c191744016c191c6d600003{?projection}", "templated": true } } } I wanted to add new element to tierLines[] Json patch request I am using is below [ { "op": "add", "path": "/tierList/0/tierLines/-", "value": { "createdBy": "RK", "creationDttm": "2019-07-22T09:56:23.000+0000", "modifiedBy": "RK", "modifiedDttm": "2019-07-22T09:56:30.000+0000", "tierId": "8a80cb816c191744016c191c6d610004", "seqNum": 1, "fromTier": 10, "toTier": 20, "tierLineId": "8a80cb816c191744016c191c6d630005", "version": 1 } } ]

Error I am getting: { "cause": null, "message": "com.ria.epPricing.entity.Tier cannot be cast to com.ria.epPricing.entity.TierLine" }

I want json after adding new element in below format: { "createdBy": "BKADMIN", "creationDttm": "2019-07-22T09:56:23.000+0000", "modifiedBy": "BKADMIN", "modifiedDttm": "2019-07-24T11:12:52.000+0000", "startDt": "2019-04-15", "endDt": "2020-03-02", "partyId": "8a80cb816c191744016c191c59bf0001", "pricelistId": "8a80cb816c191744016c191c640a0002", "priority": 1, "noOfTiers": null, "priceListName": null, "priceListShortName": null, "priceListDescription": null, "priceListTypeCd": null, "currencyCd": null, "altCurrencyCd": null, "altCurrencySw": null, "pricelistOwnerParty": null, "partyHierarchy": null, "inputPartyId": null, "partyPriceListExtensionList": [], "tierList": [ { "createdBy": "RK", "creationDttm": "2019-07-22T09:56:23.000+0000", "modifiedBy": "RK", "modifiedDttm": "2019-07-24T11:12:52.000+0000", "startDt": "2019-02-07", "endDt": null, "uom": null, "dfltCurcy": "GBP", "description": "Tier number 1", "parentId": "8a80cb816c191744016c191c6d600003", "partySpecificSw": "YES", "unitTypeCd": "VOLUME", "monthsToInclude": 1, "currMonthSw": "NO", "tierLines": [ { "createdBy": "RK", "creationDttm": "2019-07-22T09:56:23.000+0000", "modifiedBy": "RK", "modifiedDttm": "2019-07-22T09:56:30.000+0000", "tierId": "8a80cb816c191744016c191c6d610004", "seqNum": 1, "fromTier": 10, "toTier": 20, "tierLineId": "8a80cb816c191744016c191c6d630005", "version": 1 }], "tierId": "8a80cb816c191744016c191c6d610004", "version": 7 } ], "id": "8a80cb816c191744016c191c6d600003", "version": 7, "_links": { "self": { "href": "http://localhost:9090/partypricelists/8a80cb816c191744016c191c6d600003" }, "partypricelists": { "href": "http://localhost:9090/partypricelists/8a80cb816c191744016c191c6d600003{?projection}", "templated": true } } }