Java / MapStruct Java Interview questions part 2
Define a MapStruct mapper interface?
A mapper interface in MapStruct is a plain Java interface annotated with @Mapper that declares one or more abstract methods describing a source-to-target conversion. It contains no mapping logic itself; the logic is written for you by the annotation processor.
@Mapper public interface AddressMapper { AddressDto toDto(Address address); Address toEntity(AddressDto dto); }
At compile time MapStruct reads the method signatures, matches property names between Address and AddressDto, and writes an AddressMapperImpl class implementing both methods. If you never call an abstract method's implementation directly, only through this generated class, the interface itself stays free of any framework-specific code.
More Related questions...