Search code examples
javamapstruct

Mapstruct check null


I want to check null in method

@Override
public void updateFooFromNonNullAttributesOfDto(FooDto fooDto, Foo foo) {
        if ( fooDto== null ) {
            return;
        }
        if ( fooDto.getBar() != null ) {
            site.setBar( fooDto.getBar() );
        }
         if ( fooDto.getBaz() != null ) {
            site.setBar( fooDto.getBaz() );
        }
}

When I use

@Mapper(NullValueCheckStrategy.ALWAYS)

It's check in all methods, but I want check only in one... How to solve this problem?


Solution

  • This is not yet possible with MapStruct, you can either do for all or for none. There is already a feature request for the exact same thing. See 1243