forked from mapstruct/mapstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQualifier.java
More file actions
90 lines (88 loc) · 2.81 KB
/
Qualifier.java
File metadata and controls
90 lines (88 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Declares an annotation type to be a qualifier. Qualifier annotations allow unambiguously identify a suitable mapping
* method in case several methods qualify to map a bean property, iterable element etc.
* <p>
* Can be used in:
* <ul>
* <li>{@link Mapping#qualifiedBy() }</li>
* <li>{@link BeanMapping#qualifiedBy() }</li>
* <li>{@link IterableMapping#qualifiedBy() }</li>
* <li>{@link MapMapping#keyQualifiedBy() }</li>
* <li>{@link MapMapping#valueQualifiedBy() }</li>
* <li>{@link SubclassMapping#qualifiedBy() }</li>
* </ul>
* <p><strong>Example:</strong></p>
* <pre><code class='java'>
* // create qualifiers
* @Qualifier
* @Target(ElementType.TYPE)
* @Retention(RetentionPolicy.CLASS)
* public @interface TitleTranslator {}
*
* @Qualifier
* @Target(ElementType.METHOD)
* @Retention(RetentionPolicy.CLASS)
* public @interface EnglishToGerman {}
*
* @Qualifier
* @Target(ElementType.METHOD)
* @Retention(RetentionPolicy.CLASS)
* public @interface GermanToEnglish {}
* </code></pre>
* <pre><code class='java'>
* // we can create class with map methods
* @TitleTranslator
* public class Titles {
* @EnglishToGerman
* public String translateTitleEnglishToGerman(String title) {
* // some mapping logic
* }
* @GermanToEnglish
* public String translateTitleGermanToEnglish(String title) {
* // some mapping logic
* }
* }
* </code></pre>
* <pre><code class='java'>
* // usage
* @Mapper( uses = Titles.class )
* public interface MovieMapper {
* @Mapping( target = "title", qualifiedBy = { TitleTranslator.class, EnglishToGerman.class } )
* GermanRelease toGerman( OriginalRelease movies );
* }
* </code></pre>
* <pre><code class='java'>
* // generates
* 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.translateTitleEnglishToGerman( movies.getTitle() ) );
* return germanRelease;
* }
* }
* </code></pre>
*
* <b>NOTE:</b> Qualifiers should have {@link RetentionPolicy#CLASS}.
*
* @author Sjaak Derksen
* @see Named
*/
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.CLASS)
public @interface Qualifier {
}