0

I have developed a restapi using SpringBoot. I would now like implements object manipulation by jsonpatch.

In general, I would like the restrict the patch to certain properties. For example, in addition to my Person Dto, I also have a PersonPatch Dto that only contains the editable fields. Currently I do this:

  • Receive JsonPatch
  • Pull person entity from database
  • Generate PersonPatch Dto by Mapstruct
  • Apply jsonpatch to DTO and validate it
  • map PersonPatch-Dto to person-entity and save entity to database

I'm assuming this proceed is okay?

However, now I have the following problem: My Person DTO has a field called "numbers". This field now contains a list of objects of type telephone number (type, telephone number, notice).

If I now want to add a new number, it's relatively simple:

[ {
  "op": "add",
  "path": "/numbers/-",
  "value": {
    "type": "private", 
    "number": "0018181",
    "notice": "my notice"
   }
  }]

However, I have problems deleting a phone number. Here I can't say by jsonpatch "delete phone number "0018181". I must enter the id of the list element. In individual cases, this also works because I can count the list elements in the frontend. However, I get a problem if another person has made changes to the person in the meantime. My frontend then assumes that I want to delete id 3, but on the server side it is already a different id due to changes.

How can I make sure that I am really deleting the correct data when deleting?

Helotrix
  • 101
  • 1
  • 6

0 Answers0