Java / MapStruct Java Interview questions part 2
How do you troubleshoot an "Unmapped target property" warning?
This warning means a property on the target type has no source property, @Mapping rule, or usable conversion method that MapStruct could find. Working through it is mostly a process of elimination.
- Check the exact property name in the warning against the source type - a small spelling or casing difference will break automatic matching.
- If the names genuinely differ, add an explicit
@Mapping(source = "...", target = "..."). - If the property should never come from the source, add
@Mapping(target = "...", ignore = true)to document that intentionally. - If it's a nested/complex type, confirm a matching conversion method exists or is reachable via
uses.
Leaving it unresolved isn't necessarily wrong, but doing so silently invites bugs where a field is unintentionally left null in production.
More Related questions...