Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using MapStruct with big models (more than 50 fields) shared between different business use cases in my code. Depending on the entry point, some properties will be mapped and some not. When I build my project, I will always get the "WARNING: Unmapped target properties" message.

I have researched and seen that it is possible to tell the mapstruct to ignore the field by using the semantic

@Mapping(target = "propName", ignore = true)

The problem is, given my objects with so many fields, it would take a lot of code to ignore each single property in each mapper class. I also do not want this Warning on my log. Is there any way to tell mapstruct to ignore what is not mapped, avoiding this message?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can set the "unmapped target policy" on the @Mapper level or via @MapperConfig to share a setting across several mappers:

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface MyMapper {}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...