forked from mapstruct/mapstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapMapping.java
More file actions
200 lines (179 loc) · 7.57 KB
/
MapMapping.java
File metadata and controls
200 lines (179 loc) · 7.57 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* 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.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.mapstruct.control.MappingControl;
/**
* Configures the mapping between two map types, e.g. Map<String, String> and Map<Long, Date>.
*
* <p>
* <strong>Example</strong>:
* </p>
* <pre><code class='java'>
* @Mapper
* public interface SimpleMapper {
* @MapMapping(valueDateFormat = "dd.MM.yyyy")
* Map<String, String> longDateMapToStringStringMap(Map<Long, Date> source);
* }
* </code></pre>
* <pre><code class='java'>
* // generates
* public class SimpleMapperImpl implements SimpleMapper {
* @Override
* public Map<String, String> longDateMapToStringStringMap(Map<Long, Date> source) } {
* Map<String, String> map = new HashMap<String, String>(); }
* for ( java.util.Map.Entry<Long, Date> entry : source.entrySet() ) } {
* String key = new DecimalFormat( "" ).format( entry.getKey() );
* String value = new SimpleDateFormat( "dd.MM.yyyy" ).format( entry.getValue() );
* map.put( key, value );
* }
* // ...
* }
* }
* </code></pre>
*
* <p><strong>NOTE:</strong> at least one element needs to be specified</p>
*
* @author Gunnar Morling
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface MapMapping {
/**
* A format string as processable by {@link SimpleDateFormat} if the annotated method maps from a map with key type
* {@code String} to an map with key type {@link Date} or vice-versa. Will be ignored for all other key types.
*
* @return A date format string as processable by {@link SimpleDateFormat}.
*/
String keyDateFormat() default "";
/**
* A format string as processable by {@link SimpleDateFormat} if the annotated method maps from a map with value
* type {@code String} to an map with value type {@link Date} or vice-versa. Will be ignored for all other value
* types.
*
* @return A date format string as processable by {@link SimpleDateFormat}.
*/
String valueDateFormat() default "";
/**
* A format string as processable by {@link DecimalFormat} if the annotated method maps from a
* {@link Number} to a {@link String} or vice-versa. Will be ignored for all other key types.
*
* @return A decimal format string as processable by {@link DecimalFormat}.
*/
String keyNumberFormat() default "";
/**
* A format string as processable by {@link DecimalFormat} if the annotated method maps from a
* {@link Number} to a {@link String} or vice-versa. Will be ignored for all other value types.
*
* @return A decimal format string as processable by {@link DecimalFormat}.
*/
String valueNumberFormat() default "";
/**
* A key value qualifier can be specified to aid the selection process of a suitable mapper. This is useful in
* case multiple mappers (hand written of internal) qualify and result in an 'Ambiguous mapping methods found'
* error.
*
* A qualifier is a custom annotation and can be placed on either a hand written mapper class or a method.
*
* @return the qualifiers
* @see Qualifier
*/
Class<? extends Annotation>[] keyQualifiedBy() default { };
/**
* String-based form of qualifiers; When looking for a suitable mapping method to map this map mapping method's key
* type, MapStruct will only consider those methods carrying directly or indirectly (i.e. on the class-level) a
* {@link Named} annotation for each of the specified qualifier names.
* <p>
* Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and
* are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large
* number of qualifiers as no custom annotation types are needed.
*
* @return One or more qualifier name(s)
* @see #keyQualifiedBy()
* @see Named
*/
String[] keyQualifiedByName() default { };
/**
* A value qualifier can be specified to aid the selection process of a suitable mapper for the values in the map.
* This is useful in case multiple mappers (hand written of internal) qualify and result in an 'Ambiguous mapping
* methods found' error.
* <p>
* A qualifier is a custom annotation and can be placed on either a hand written mapper class or a method.
*
* @return the qualifiers
* @see Qualifier
*/
Class<? extends Annotation>[] valueQualifiedBy() default { };
/**
* String-based form of qualifiers; When looking for a suitable mapping method to map this map mapping method's
* value type, MapStruct will only consider those methods carrying directly or indirectly (i.e. on the class-level)
* a {@link Named} annotation for each of the specified qualifier names.
* <p>
* Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and
* are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large
* number of qualifiers as no custom annotation types are needed.
*
* @return One or more qualifier name(s)
* @see #valueQualifiedBy()
* @see Named
*/
String[] valueQualifiedByName() default { };
/**
* Specifies the type of the key to be used in the result of the mapping method in case multiple mapping
* methods qualify.
*
*
* @return the resultType to select
*/
Class<?> keyTargetType() default void.class;
/**
* Specifies the type of the value to be used in the result of the mapping method in case multiple mapping
* methods qualify.
*
*
* @return the resultType to select
*/
Class<?> valueTargetType() default void.class;
/**
* The strategy to be applied when {@code null} is passed as source value to this map mapping. If no
* strategy is configured, the strategy given via {@link MapperConfig#nullValueMappingStrategy()} or
* {@link Mapper#nullValueMappingStrategy()} will be applied, using {@link NullValueMappingStrategy#RETURN_NULL}
* by default.
*
* @return The strategy to be applied when {@code null} is passed as source value to the methods of this mapping.
*/
NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL;
/**
* Allows detailed control over the key mapping process.
*
* @return the mapping control
*
* @since 1.4
* @see org.mapstruct.control.DeepClone
* @see org.mapstruct.control.NoComplexMapping
* @see org.mapstruct.control.MappingControl
*/
Class<? extends Annotation> keyMappingControl() default MappingControl.class;
/**
* Allows detailed control over the value mapping process.
*
* @return the mapping control
*
* @since 1.4
*
* @see org.mapstruct.control.DeepClone
* @see org.mapstruct.control.NoComplexMapping
* @see org.mapstruct.control.MappingControl
*/
Class<? extends Annotation> valueMappingControl() default MappingControl.class;
}