Package org.mapstruct
Enum CollectionMappingStrategy
- java.lang.Object
-
- java.lang.Enum<CollectionMappingStrategy>
-
- org.mapstruct.CollectionMappingStrategy
-
- All Implemented Interfaces:
Serializable
,Comparable<CollectionMappingStrategy>
public enum CollectionMappingStrategy extends Enum<CollectionMappingStrategy>
Strategy for propagating the value of collection-typed properties from source to target.- Author:
- Sjaak Derksen
-
-
Enum Constant Summary
Enum Constants Enum Constant Description ACCESSOR_ONLY
The setter of the target property will be used to propagate the value:orderDto.setOrderLines(order.getOrderLines)
.ADDER_PREFERRED
Identical toSETTER_PREFERRED
, only that adder methods will be preferred over setter methods, if both are present for a given collection-typed property.SETTER_PREFERRED
If present, the setter of the target property will be used to propagate the value:orderDto.setOrderLines(order.getOrderLines)
.TARGET_IMMUTABLE
Identical toSETTER_PREFERRED
, however the target collection will not be cleared and accessed via addAll in case of updating existing bean instances, see:MappingTarget
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CollectionMappingStrategy
valueOf(String name)
Returns the enum constant of this type with the specified name.static CollectionMappingStrategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
ACCESSOR_ONLY
public static final CollectionMappingStrategy ACCESSOR_ONLY
The setter of the target property will be used to propagate the value:orderDto.setOrderLines(order.getOrderLines)
.If no setter is available but a getter method, this will be used, under the assumption it has been initialized:
orderDto.getOrderLines().addAll(order.getOrderLines)
. This will also be the case when usingMappingTarget
(updating existing instances).
-
SETTER_PREFERRED
public static final CollectionMappingStrategy SETTER_PREFERRED
If present, the setter of the target property will be used to propagate the value:orderDto.setOrderLines(order.getOrderLines)
.If no setter but and adder method is present, that adder will be invoked for each element of the source collection:
order.addOrderLine(orderLine() )
.If neither a setter nor an adder method but a getter for the target property is present, that getter will be used, assuming it returns an initialized collection: If no setter is available, MapStruct will first look for an adder method before resorting to a getter.
-
ADDER_PREFERRED
public static final CollectionMappingStrategy ADDER_PREFERRED
Identical toSETTER_PREFERRED
, only that adder methods will be preferred over setter methods, if both are present for a given collection-typed property.
-
TARGET_IMMUTABLE
public static final CollectionMappingStrategy TARGET_IMMUTABLE
Identical toSETTER_PREFERRED
, however the target collection will not be cleared and accessed via addAll in case of updating existing bean instances, see:MappingTarget
. Instead the target accessor (e.g. set) will be used on the target bean to set the collection.
-
-
Method Detail
-
values
public static CollectionMappingStrategy[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (CollectionMappingStrategy c : CollectionMappingStrategy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CollectionMappingStrategy valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
-