Despite lack of any form of feedback, I have been plodding along with this
idea, and (as per some other comments) am thinking of implementing this via
@JsonSetter, like so:

public class Foo {
   @JsonSetter(nulls=Nulls.SKIP) // as per name, do NOT assign
   public String name = "#default#";
}

and as an added bonus, also allow further null-avoidance like so:

public class Listy {
   @JsonSetter(nulls=Nulls.FAIL, contentNulls=Nulls.SKIP)
   public List<String> names;
}

which would throw an exception if an attempt was made to bind `null` for
"names"; but further weed out any `null`s from within values.

This, together with allowing mergeability (that is, first trying to see if
property has a value; if so, using that instead of constructing new) should
allow much better defaulting of values.
And keep those nulls away from your free-range artisan Data Structeurs.

-+ Tatu +-


On Thu, Sep 22, 2016 at 3:28 PM, Tatu Saloranta <[email protected]> wrote:

> Ok: JVM `null`s do not get much love. There are many null-hates,
> discrimination. So, with heavy heart (for I do not do that!), I concur that
> maybe Jackson ought to do something to allow further discrimination of null
> values, besides on constant flow of all kinds of proposals.
>
> My idea-of-the-day is as follows: what if there was a way to do something
> like
>
> public class POJO {
>      @JsonFormat(without=JsonFormat.Feature.ALLOW_NULL_ASSIGNMENT)
>     protected String name = "N/A";
> }
>
> which, upon deserialization encountering:
>
> { "name" : null }
>
> would just ignore that value?
>
> Would this be considered useful? If so, we could also add hierarchic
> system to allow:
>
> 1. Global default (to have by default rule of no null assignments)
> 2. Per-type overrides (via configOverrides() added in 2.7)
> 3. Per-property overrides via JsonFormat
>
> Which, I suspect, would cover lots of null-avoidance use cases (*)
>
> WDYT?
>
> -+ Tatu +-
>
> (*) and no doubt spring new ones like "ignore not just nulls but also
> Empty String; number 0; or Date of today" offshoots. But one problem at a
> time
>
>
>
>

-- 
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