Package org.mapstruct
Enum NullValuePropertyMappingStrategy
- java.lang.Object
-
- java.lang.Enum<NullValuePropertyMappingStrategy>
-
- org.mapstruct.NullValuePropertyMappingStrategy
-
- All Implemented Interfaces:
Serializable
,Comparable<NullValuePropertyMappingStrategy>
public enum NullValuePropertyMappingStrategy extends Enum<NullValuePropertyMappingStrategy>
Strategy for dealing withnull
or not present properties in the source bean. TheNullValuePropertyMappingStrategy
can be defined onMapperConfig
,Mapper
,BeanMapping
andMapping
. Precedence is arranged in the reverse order. SoMapping
will overrideBeanMapping
, will overideMapper
The enum only applies to update methods: methods that update a pre-existing target (annotated with@
MappingTarget
).Note: some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see
CollectionMappingStrategy
, MapStruct will always generate a source property null check, regardless the value of theNullValuePropertyMappingStrategy
to avoid addition ofnull
to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied.- Since:
- 1.3
- Author:
- Sjaak Derksen
-
-
Enum Constant Summary
Enum Constants Enum Constant Description IGNORE
If a source bean property equalsnull
the target bean property will be ignored and retain its existing value.SET_TO_DEFAULT
If a source bean property equalsnull
the target bean property will be set to its default value.SET_TO_NULL
If a source bean property equalsnull
the target bean property will be set explicitly tonull
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static NullValuePropertyMappingStrategy
valueOf(String name)
Returns the enum constant of this type with the specified name.static NullValuePropertyMappingStrategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
SET_TO_NULL
public static final NullValuePropertyMappingStrategy SET_TO_NULL
If a source bean property equalsnull
the target bean property will be set explicitly tonull
.
-
SET_TO_DEFAULT
public static final NullValuePropertyMappingStrategy SET_TO_DEFAULT
If a source bean property equalsnull
the target bean property will be set to its default value.This means:
- For
List
MapStruct generates anArrayList
- For
Map
aHashMap
- For arrays an empty array
- For
String
""
- for primitive / boxed types a representation of
0
orfalse
- For all other objects an new instance is created, requiring an empty constructor.
Make sure that a
Mapping.defaultValue()
is defined if no empty constructor is available on the default value. - For
-
IGNORE
public static final NullValuePropertyMappingStrategy IGNORE
If a source bean property equalsnull
the target bean property will be ignored and retain its existing value.
-
-
Method Detail
-
values
public static NullValuePropertyMappingStrategy[] 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 (NullValuePropertyMappingStrategy c : NullValuePropertyMappingStrategy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static NullValuePropertyMappingStrategy 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
-
-