File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -337,3 +337,21 @@ the method `doSomething` will be ignored by MapStruct.
337337
338338{{% /faq_question %}}
339339
340+ {{% faq_question "How do I write a Spring Extension Converter using MapStruct's @Context feature?" %}}
341+
342+ The unfortunate short answer: You can't.
343+ Spring's [ Converter definition] ( https://docs.spring.io/spring-framework/reference/core/validation/convert.html#core-convert-Converter-API )
344+ only allows for a ` convert ` method that has a single input parameter (the source object) and returns the converted (mapped) response.
345+
346+ If you ever find yourself in a situation where you'd like to combine Spring's ` Converter ` and MapStruct's ` @context `
347+ concepts, your options are:
348+
349+ * Instead of supplying a ` @Context ` object as parameter, consider injecting it.
350+ * If injecting the object is no option, sometimes you may be able to inject some form of modifiable wrapper object that
351+ can be given the ` @Contet ` object at runtime.
352+ * If neither of the above two are possible and you can't implement a mapping without a ` @Context ` object, you should
353+ stick to MapStruct's core functionality and refrain from letting this particular Mapper extend the ` Converter `
354+ interface.
355+
356+ {{% /faq_question %}}
357+
You can’t perform that action at this time.
0 commit comments