modelmapper null value skip

AchuSai picture AchuSai · Dec 14, 2017 · Viewed 11.6k times · Source
Class A {
    private String a;
    private String b;
    private B innerObject;
}
Class B {
    private String c;
}

In my case, String b might come in with a null value. My modelmapper configuration is like below:

ModelMapper mapper = new ModelMapper();
    mapper.getConfiguration()
    .setFieldMatchingEnabled(true)
    .setMatchingStrategy(MatchingStrategies.LOOSE)
    .setFieldAccessLevel(AccessLevel.PRIVATE)
    .setSkipNullEnabled(true)
    .setSourceNamingConvention(NamingConventions.JAVABEANS_MUTATOR);

when I map the object, I get the target object with b=null value.

Trying to stay away from a strategy shown here: SO- Question

What am I missing?

Answer

TequilaLime picture TequilaLime · Jul 27, 2018

Have you tried this configuration:

modelMapper.getConfiguration().setPropertyCondition(Conditions.isNotNull());