Force null value check on field mapping in Mapstruct

1 · Adrian Matei · Sept. 2, 2021, 4:48 a.m.
Use the nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) on the mapping property you want to be checked. In this snippet you can see a PostalAdress entity is mapped to an entity of the same type, but the id is overwritten only when it is present in the source: import java.time.LocalDateTime; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.NullValueCheckStrategy; import com.example.entity.PostalAddress; @Mapper( componentModel = "cdi", imports = ...