Java / MapStruct Java Interview questions part 2
List the annotations commonly used with MapStruct?
A handful of annotations cover most day-to-day mapping needs.
| Annotation | Purpose |
@Mapper | Marks the mapper interface/class. |
@Mapping | Configures one property mapping (rename, ignore, format, etc.). |
@MappingTarget | Marks a parameter as the object to update in place. |
@BeforeMapping / @AfterMapping | Runs custom code before/after generated mapping logic. |
@InheritConfiguration | Reuses another method's @Mapping rules. |
@InheritInverseConfiguration | Derives the reverse mapping's configuration. |
@Named / @ValueMapping | Disambiguates custom methods / configures enum mapping. |
Most everyday mappers only ever need @Mapper and a handful of @Mapping annotations; the lifecycle hooks and inheritance annotations tend to show up once a codebase has several mappers that share rules or need custom logic layered around the generated code.
More Related questions...