I have the following mapper
@Mapper(config = MappingConfig.class)
public interface PokerRoomMapper {
@Mapping(target = "phase", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
PokerRoom pokerRoomDtoToPokerRoom(PokerRoomDto pokerRoomDto);
}
The pokerRoomDto which is passed to it has a "phase" field which can be null. I want this field to be ignored when it is null. But right now the "null" value still gets mapped to the pokerRoom entity.
If I just ignore the field in the mapper it works and the default value for phase in PokerRoom stays untouched however I dont want to always ignore it.
@Mapper(config = MappingConfig.class)
public interface PokerRoomMapper {
@Mapping(target = "phase", ignore = true)
PokerRoom pokerRoomDtoToPokerRoom(PokerRoomDto pokerRoomDto);
}
PokerRoom
have default value? If not then I am not sure how you workout that the mapping is not working. If mapstruct ignores a field during mapping which has no default value then it will be null after mapping anyway – Apia