I noticed that many of the answers provided are all JSON fixes or incomplete answers. Below is a full explanation and an example of what you need to work with real code.
First of all, PATCH is a selective PUT. You use it to update any number of fields for an object or list of objects. In PUT, you usually send the entire object with any updates.
PATCH / object / 7
{ "objId":7, "objName": "New name" }
PUT / object / 7
{ "objId":7, "objName": "New name", "objectUpdates": true, "objectStatus": "ongoing", "scoring": null, "objectChildren":[ { "childId": 1 }, ............ }
This allows you to update records without a huge number of endpoints. For example, using the above, to update the score, you need the / {id} / scoring object, then to update the name you need the / {id} / name object. There is literally one endpoint for each item, or you require the interface to send an entire object for each update. If you have a huge object, it can take a lot of time on the network or mobile data that is not needed. The patch allows you to have 1 endpoint with the minimum values of the object properties that the mobile platform should use.
Here is an example of the actual use of the patch:
@ApiOperation(value = "Patch an existing claim with partial update") @RequestMapping(value = CLAIMS_V1 + "/{claimId}", method = RequestMethod.PATCH) ResponseEntity<Claim> patchClaim(@PathVariable Long claimId, @RequestBody Map<String, Object> fields) {
The above can be confusing for some people, as new developers usually do not deal with this reflection. In fact, no matter what you pass to this function in the body, it will find the corresponding statement using the given identifier, and then ONLY update the fields that you pass as a key-value pair.
Body example:
PATCH / CLAIM / 7
{ "claimId":7, "claimTypeId": 1, "claimStatus": null }
The above will update ApplicTypeId and ClausStatus to the indicated values for clause 7, leaving all other values unchanged.
So the return will be something like this:
{ "claimId": 7, "claimSrcAcctId": 12345678, "claimTypeId": 1, "claimDescription": "The vehicle is damaged beyond repair", "claimDateSubmitted": "2019-01-11 17:43:43", "claimStatus": null, "claimDateUpdated": "2019-04-09 13:43:07", "claimAcctAddress": "123 Sesame St, Charlotte, NC 28282", "claimContactName": "Steve Smith", "claimContactPhone": "777-555-1111", "claimContactEmail": " steve.smith@domain.com ", "claimWitness": true, "claimWitnessFirstName": "Stan", "claimWitnessLastName": "Smith", "claimWitnessPhone": "777-777-7777", "claimDate": "2019-01-11 17:43:43", "claimDateEnd": "2019-01-11 12:43:43", "claimInvestigation": null, "scoring": null }
As you can see, the complete object would return without changing any data other than what you want to change. I know that there is a slight repetition, I just wanted to outline it clearly.