mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
This commit is contained in:
parent
84062bf78f
commit
c153c8bf5a
@ -18,6 +18,10 @@ import java.lang.annotation.Target;
|
||||
* If no method can be identified unambiguously as configuration source (i.e. several candidate methods with matching
|
||||
* source and target type exist), the name of the method to inherit from must be specified via {@link #name()}.
|
||||
* <p>
|
||||
* {@link Mapping#expression()}, {@link Mapping#constant()}, {@link Mapping#defaultExpression()} and
|
||||
* {@link Mapping#defaultValue()} are not inverse inherited
|
||||
*
|
||||
* <p>
|
||||
* A typical use case is annotating an update method so it inherits all mappings from a corresponding "standard" mapping
|
||||
* method:
|
||||
*
|
||||
|
@ -21,9 +21,12 @@ import java.lang.annotation.Target;
|
||||
* <p>
|
||||
* If more than one matching inverse method exists, the name of the method to inherit the configuration from must be
|
||||
* specified via {@link #name()}
|
||||
* <p>
|
||||
* {@link Mapping#expression()}, {@link Mapping#constant()}, {@link Mapping#defaultExpression()} and
|
||||
* {@link Mapping#defaultValue()} are not inverse inherited
|
||||
*
|
||||
* <p>
|
||||
* <strong>Example</strong>
|
||||
* <strong>Examples</strong>
|
||||
* </p>
|
||||
* <pre><code class='java'>
|
||||
* @Mapper
|
||||
@ -56,7 +59,21 @@ import java.lang.annotation.Target;
|
||||
* }
|
||||
* }
|
||||
* </code></pre>
|
||||
* <p>
|
||||
* <pre><code class='java'>
|
||||
* @Mapper
|
||||
* public interface CarMapper {
|
||||
*
|
||||
* @Mapping( target = "seatCount", source = "numberOfSeats")
|
||||
* @Mapping( target = "enginePower", source = "engineClass", ignore=true) // NOTE: source specified as well
|
||||
* CarDto carToDto(Car car);
|
||||
*
|
||||
* @InheritInverseConfiguration
|
||||
* @Mapping(target = "numberOfSeats", ignore = true)
|
||||
* // no need to specify a mapping with ignore for "engineClass": specifying source above will assume
|
||||
* Car carDtoToCar(CarDto carDto);
|
||||
* }
|
||||
* </code></pre>
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
|
@ -78,13 +78,15 @@ If multiple methods qualify, the method from which to inherit the configuration
|
||||
|
||||
Configurations are inherited transitively. So if method `C` defines a mapping `@Mapping( target = "x", ignore = true)`, `B` defines a mapping `@Mapping( target = "y", ignore = true)`, then if `A` inherits from `B` inherits from `C`, `A` will inherit mappings for both property `x` and `y`.
|
||||
|
||||
Expressions and constants are excluded (silently ignored) in `@InheritInverseConfiguration`.
|
||||
`@Mapping#expression`, `@Mapping#defaultExpression`, `@Mapping#defaultValue` and `@Mapping#constant` are excluded (silently ignored) in `@InheritInverseConfiguration`.
|
||||
|
||||
`@Mapping#ignore` is only applied when `@Mapping#source` is also present in `@InheritInverseConfiguration`.
|
||||
|
||||
Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2 release. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
`@InheritConfiguration` or `@InheritInverseConfiguration` cannot refer to methods in a used mapper.
|
||||
`@InheritInverseConfiguration` cannot refer to methods in a used mapper.
|
||||
====
|
||||
|
||||
[[shared-configurations]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user