Moin!
We run actually into the same problem recently. I wrote a container
object like Optional which allows you to distinguish between value not
given and an explicit null. I am trying to open source it, please give
me a day or two ;)
It would look in your case like this:
private ValueWithNull<Boolean> flag;
If null is explicitly set, you can check it with a method call on flag.
If flag is absent, it will be null.
Cheers
Ruwen
On 30/04/18 03:27, Garret Wilson 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
<https://tools.ietf.org/html/rfc7396> as I understand it.
So I added jackson-datatype-jdk8 and added a POJO DTO FooBar in Java
that has:
|
publicOptional<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 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]
<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.
--
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.