On Fri, Mar 5, 2021 at 10:22 AM Marcelo Carabolante
<[email protected]> wrote:
>
> Hello folks,
>
> Is there any way to configure Jackson to treat null/missing list a empty 
> collection?
>
> context: we are using immutable objects, so its constructor based 
> deserialization.
>
> I tried a few stuff, but I always seems to hit a wall.

If what you want is to allow handling missing/null Collection value(s)
by one of:

1. Replace with default "empty" value
2. Throw exception
3. Skip assignment (for setter/field), to leave at default (presumable
empty) value

then what you want is the special form of `@JsonSetter` annotation (or
matching "config override" configuration).
It was added in 2.9, and explained on:

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

So you'd add:

   @JsonSetter(nulls=Nulls.AS_EMPTY)

on the specific accessor (field, setter, constructor parameter).
To handle the case of missing values (as opposed to just explicitly
received `null`s), you will need to apply it to constructor parameter.

Hope this helps,

-+ Tatu +-



>
> Thanks!
>
>
> ________________________________
> This email and any files transmitted with it contain confidential information 
> and/or privileged or personal advice. This email is intended for the 
> addressee(s) stated above only. If you are not the addressee of the email 
> please do not copy or forward it or otherwise use it or any part of it in any 
> form whatsoever. If you have received this email in error please notify the 
> sender and remove the e-mail from your system. Thank you.
>
> This is an email from the company Just Eat Takeaway.com N.V., a public 
> limited liability company with corporate seat in Amsterdam, the Netherlands, 
> and address at Oosterdoksstraat 80, 1011 DK Amsterdam, registered with the 
> Dutch Chamber of Commerce with number 08142836 and where the context 
> requires, includes its subsidiaries and associated undertakings.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/f94adfef-e4be-4210-9b2e-62c87a3dd1c5n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10gu-Dig-hspBX-WGWWBgNEZqesvvF1PgLpbRvJd49jz5w%40mail.gmail.com.

Reply via email to