You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/docs/asciidoc/chapter-3-mapper-as-converter.asciidoc
+44-2Lines changed: 44 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,10 +142,12 @@ public interface MapperSpringConfig {
142
142
143
143
When the `conversionServiceBeanName` property is set, the built-in <<converterScan>> cannot be used in tests as it does not pick up this property.
144
144
However, setting the property `generateConverterScan` to `true` will create an alternative inside the project.
145
-
Important to note: This version will _not_ create a `ConversionService` with the given bean name, but merely register all Mappers with the bean identified by the given name. This leads to two practical differences:
145
+
Important to note: This version will _not_ create a `ConversionService` with the given bean name, but merely register all Mappers with the bean identified by the given name.
146
+
This leads to two practical differences:
146
147
147
148
- Unlike its <<testExtensions>> counterpart, this version is perfectly suited to be used in production code.
148
149
- In a test, the developer will still have to provide a `ConfigurableConversionService` themselves, e.g.:
150
+
149
151
====
150
152
[source,java,linenums]
151
153
[subs="verbatim,attributes"]
@@ -166,4 +168,44 @@ public class ConversionServiceAdapterIntegrationTest {
166
168
private ConversionService conversionService;
167
169
}
168
170
----
169
-
====
171
+
====
172
+
173
+
[[adapterMethodName]]
174
+
=== Modifying the name for the generated adapter method
175
+
176
+
By default, the adapter class will contain method names of the form `map<SourceTypeName>To<targetTypeName>`.
177
+
If you wish to change this, you can do so on a per-Mapper basis by applying the annotation `@AdapterMethodName`:
178
+
179
+
====
180
+
[source,java,linenums]
181
+
[subs="verbatim,attributes"]
182
+
----
183
+
@Mapper(config = MapperSpringConfig.class)
184
+
@AdapterMethodName("toDto")
185
+
public interface WheelMapper extends Converter<Wheel, WheelDto> {
186
+
@Override
187
+
WheelDto convert(Wheel source);
188
+
}
189
+
----
190
+
====
191
+
192
+
This changes the generated method name to be the annotation's `value` attribute:
193
+
194
+
====
195
+
[source,java,linenums]
196
+
[subs="verbatim,attributes"]
197
+
----
198
+
@Component
199
+
public class ConversionServiceAdapter {
200
+
private final ConversionService conversionService;
201
+
202
+
public ConversionServiceAdapter(@Lazy final ConversionService conversionService) {
Copy file name to clipboardExpand all lines: examples/external-conversions/src/main/java/org/mapstruct/extensions/spring/example/externalconversions/MapstructConfig.java
0 commit comments