#945 Adding clarification that Java 8 is needed for default methods

This commit is contained in:
Gunnar Morling 2016-11-01 19:08:06 +01:00
parent fff7457286
commit a928ff56d7

View File

@ -337,7 +337,7 @@ MapStruct takes all public properties of the source and target types into accoun
In some cases it can be required to manually implement a specific mapping from one type to another which can't be generated by MapStruct. One way for this is to implement such method on another class which then is used by mappers generated by MapStruct (see <<invoking-other-mappers>>).
Alternatively you can implement custom methods directly in a mapper interface as default methods. The generated code will invoke the default methods if the argument and return types match.
Alternatively, when using Java 8 or later, you can implement custom methods directly in a mapper interface as default methods. The generated code will invoke the default methods if the argument and return types match.
As an example let's assume the mapping from `Person` to `PersonDto` requires some special logic which can't be generated by MapStruct. You could then define the mapper from the previous example like this:
@ -359,7 +359,7 @@ public interface CarMapper {
----
====
The class generated by MapStruct implements method `carToCarDto()`. The generated code in `carToCarDto()` will invoke the manually implemented `personToPersonDto()` method when mapping the `driver` attribute.
The class generated by MapStruct implements the method `carToCarDto()`. The generated code in `carToCarDto()` will invoke the manually implemented `personToPersonDto()` method when mapping the `driver` attribute.
A mapper could also be defined in form of an abstract class instead of an interface and implement custom methods directly in this mapper class. In this case MapStruct will generate an extension of the abstract class with implementations of all abstract methods. An advantage of this approach over declaring default methods is that additional fields could be declared in the mapper class.