On Sun, Apr 29, 2018 at 10:27 AM, Garret Wilson <[email protected]> wrote:
> I'm wanting to support a `PATCH` method on the server using JAX-RS with
> RESTEasy. I will do all the patching myself manually; I just need to read in
> a JSON document and figure out if a particular property is set to `null` or
> if it's missing. If the property is set to `null`, I will remove the value
> from the database. If the property isn't set to anything, I will leave it
> untouched in the database. That's pretty much the gist of JSON Merge Patch
> as I understand it.
>
> So I added jackson-datatype-jdk8 and added a POJO DTO FooBar in Java that
> has:
>
> public Optional<Boolean> flag = null;
>
> Based on https://github.com/FasterXML/jackson-datatype-jdk8/issues/2 , I
> assumed that if the incoming JSON did not indicate a "flag", then in Java
> the "flag" property would be left as null.
>
> But using com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.5, unless
> I misinterpreted something, if I send a JSON document {} to the server,
> Jackson will construct a FooBar object, not with flag == null as I would
> expect, but with flag == Optional.of(false). So there's no way to tell if
> the incoming JSON patch document was {} or if it was {"flag":false}.
>
> How can I tell the difference?

You will need to use `mapper.updateValue` (or, `ObjectReader` created
with `readerForUpdating(existingValue)`
to apply merge.

For more complex updates, however, more is needed since this is only
shallow update.
This is possible with Jackson 2.9, as per "merging" section of:

https://medium.com/@cowtowncoder/jackson-2-9-features-b2a19029e9ff

I hope this helps,

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to