Java / MapStruct Java Interview questions part 2
How do you ignore a target field during mapping?
Set ignore = true on a @Mapping annotation targeting that property, so the generated code simply skips assigning it.
@Mapping(target = "createdAt", ignore = true) OrderDto toDto(Order order);
This is typically used for fields that are set elsewhere, such as timestamps, generated IDs, or security-sensitive values that should never come from a plain bean mapping. Ignoring a property also prevents MapStruct from emitting an "unmapped target property" warning for it, which keeps the build output clean for properties you skipped on purpose rather than by accident.
More Related questions...