1

I have a Spring Boot application in which I want to enable the JSON Patching of multiple resources at the same time, as described in this question. My endpoint accepts a javax.json.JsonPatch as parameter and returns 204 NO CONTENT upon success.

Now, my collection patching strategy is:

  1. Obtain the id of each entity that needs to be updated, which can be found in the path component of the JsonPatch object.
  2. Fetch all the entities with the given ids.
  3. Convert each entity to its JSON representation.
  4. Apply the corresponding patch.
  5. Persist the updated entities.

My question is how can I obtain all the entity ids from the path attribute of the objects, if that is possible without doing regex parsing or other such string manipulating operations?

If this is not the best approach at patching several documents in the same operation, could you provide a better strategy?

Thanks!

Daniel Pop
  • 456
  • 1
  • 6
  • 23
  • I have the same question. E.g. PATCH /users [{"op":"replace","path":"/user1/location","value":"home"},{"op":"replace","path":"/user2/location","value":"work"}]. – johnr Feb 13 '23 at 21:51

1 Answers1

0

Why you need to put the ids inside the jsonPatch? I suggest to accept a Map<String,JsonPatch> where String key is your entity Id and JsonPatch value the list of the operations to perform on that entity.

Michael Cauduro
  • 185
  • 1
  • 3
  • 16