toedter / spring-hateoas-jsonapi

A JSON:API media type implementation for Spring HATEOAS
Apache License 2.0
107 stars 15 forks source link

Revert value to null in PATCH #77

Closed cgendreau closed 1 year ago

cgendreau commented 1 year ago

We are trying to achieve something very similar to #51 where we need to change back a value to null (could be a relationship or an attribute). If we take the Movie example, one could imagine setting the imdbId to ABC and then trying to setting it to null. So a mechanism would be required to differentiate a value that is set to null vs an attribute that was not provided in the PATCH that is null due to its initial value.

The OptionalProperty suggested in #51 is one way to achieve that. Another way may be to preserve the keys from the Map<String, Object> that is sent to Jackson in AbstractJsonApiModelDeserializer. Something like an augmented EntityModel could offer a way to check if an attribute/relationship was explicitly provided. Far from perfect, I'm more wondering about potential solution.

Thanks for the library!

toedter commented 1 year ago

Thx, since the proposed solution of #51 could be applied, I close this issue. Please re-open when you require changes in the library.

cgendreau commented 1 year ago

Thanks for your response. We tried couple of different options and preserving the keys of the JSON:API document seems to be the easiest way to accommodate that.

If possible, it would be interesting to see what was available here (from #51) (it's not available anymore):

I have created a little demo with your example (including serialization and patch method), you can download it at https://my.hidrive.com/share/ylcmjtbywn