4

I am relatively new in Spring Boot. I am developing a simple user management system and want to replace my PUT requests with PATCH ones.

As I read here: Custom Spring MVC HTTP Patch requests with Spring Data Rest functionality. A simple way to do it, is to convert to JSON the current state of the user, apply the JSON from the PATCH query and then convert that to my class for users. For the first and the last, I know how to do them - using ObjectMapper as described here: http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson/.

However, I am not exactly sure how to apply the patch. I read about JsonPatchHandler, but there isn't a good manual for how to use it, so I don't know how to use it. Can someone explain how can I use it, or tell me another way to handle a PATCH request?

Community
  • 1
  • 1
Ivan Ivanov
  • 243
  • 4
  • 15

1 Answers1

3

Actually it turned out that there are two types of PATCH requests. The first type are HTTP PATCH requests, which are described here: https://www.rfc-editor.org/rfc/rfc5789 and there: http://restcookbook.com/HTTP%20Methods/patch/. I needed exactly those types of queries and managed to handle them using a Map, as described here: How to do PATCH properly in strongly typed languages based on Spring - example in the simple solution.

The second type of PATCH requests are the JSON ones. They are a little more complicated and are described here: https://www.rfc-editor.org/rfc/rfc6902. They are the ones that are supposed to be handled using JsonPatch and the method I asked in my question.

Community
  • 1
  • 1
Ivan Ivanov
  • 243
  • 4
  • 15