jasminb / jsonapi-converter

JSONAPI-Converter is a Java/Android library that provides support for working with JSONAPI spec
Apache License 2.0
272 stars 81 forks source link

PATCH Updates of to null values? #220

Open bensullivan opened 4 years ago

bensullivan commented 4 years ago

Hi

We have a requirement where a field may need to be cleared of its value - essentially setting it to null.

According to JSON:API spec, I should ensure the server accommodates partial updates (PATCH).

When I don't submit a value for a field I don't want to update in the PATCH request, along with a field I want to set to null and the deserialize the resource, unsurprisingly I can't tell which properties are needed to set to null and which were just not submitted in the PATCH request.

I understand nulls suck and I've already confirmed with the product owner that there is a business driver behind this requirement :-(

Going a bit nuts here - so I wondering if this is something that anyone has come across before.

Is it possible to do something like default the Resource properties to Optional.empty() and then if a null value is deserialized then I know I have to update that and ignore all the other optionals?

Many thanks

Ben

bensullivan commented 4 years ago

Seems like this is relevant...

https://github.com/jasminb/jsonapi-converter/issues/168

bensullivan commented 4 years ago

I also thought about using queryParams to handle the specific case of patching to null values - it's not JSON:API but will save me some sanity :-)