Why does http PATCH reset double properties to 0 with jpa/spring mvc? -


When I patch an HTTP for this model to update the value "bar" then it works as expected Does.

  @Entity @Table (name = 'Foo') square Foo {@Id string id = UUID.randomUUID (double bar string barge}}  

Instead, I do a patch at the same end point, but only by default in the database (leaving barring completely with payload) and returning JSON shows that the bar value is set to 0

Did anyone know that why a patch would update double value without it being in the body?

I am using the default stack at this time (Data-JPA / Security / Web) / w / Spring-boot 1.1.6 ships

< Div class = "post-text" itemprop = "text">

When you do a patch, the following happens:

  • Foo is populated with all the values ​​that have been sent with the request
  • Doo is loaded by the unit URI with the id expatire
  • < Li> All the properties that vary between the two objects are new Foo to Foo , as long as the value is not null new foo .

As you have seen, the simple algorithm is extremely problematic when it comes to primitive values ​​or any default value. Bar will always be a new Foo in the example 0 and therefore if the replacement value is not 0 then it will be copied . The problem is so big that someone could imagine imagine was the default value of , such as "" .

In your answer primarily involves a possible solution for primitives, but unfortunately you can not normally cover the default value. IMHO is a serious bug due to laziness.


Comments