Package org.mapstruct
Annotation Type Named
Marks mapping methods with the given qualifier name. Can be used to qualify a single method or all methods of a given
type by specifying this annotation on the type level.
Will be used to select the correct mapping methods when mapping a bean property type, element of an iterable type or the key/value of a map type.
Example (both methods of Titles are capable to convert a string, but the ambiguity is resolved by applying
the qualifiers in @Mapping:
@Named("TitleTranslator")
public class Titles {
@Named("EnglishToGerman")
public String translateTitleEG(String title) {
// some mapping logic
}
@Named("GermanToEnglish")
public String translateTitleGE(String title) {
// some mapping logic
}
}
@Mapper( uses = Titles.class )
public interface MovieMapper {
@Mapping( target = "title", qualifiedByName = { "TitleTranslator", "EnglishToGerman" } )
GermanRelease toGerman( OriginalRelease movies );
}
The following implementation of MovieMapper will be generated:
public class MovieMapperImpl implements MovieMapper {
private final Titles titles = new Titles();
@Override
public GermanRelease toGerman(OriginalRelease movies) {
if ( movies == null ) {
return null;
}
GermanRelease germanRelease = new GermanRelease();
germanRelease.setTitle( titles.translateTitleEG( movies.getTitle() ) );
return germanRelease;
}
}
- Author:
- Sjaak Derksen
- See Also:
-
Required Element Summary
Required Elements
-
Element Details
-
value
String valueA name qualifying the annotated element- Returns:
- the name.
-