Package org.mapstruct
Enum NullValuePropertyMappingStrategy
- All Implemented Interfaces:
Serializable,Comparable<NullValuePropertyMappingStrategy>,java.lang.constant.Constable
Strategy for dealing with
null or not present properties in the source bean. The
NullValuePropertyMappingStrategy can be defined on MapperConfig, Mapper, BeanMapping
and Mapping.
Precedence is arranged in the reverse order. So Mapping will override BeanMapping, will
override Mapper
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 the NullValuePropertyMappingStrategy to avoid addition of null
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
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionIf a source bean property equalsnullthe target bean property will be cleared.If a source bean property equalsnullthe target bean property will be ignored and retain its existing value.If a source bean property equalsnullthe target bean property will be set to its default value.If a source bean property equalsnullthe target bean property will be set explicitly tonullorOptional.empty()in case the target type is anOptional. -
Method Summary
Modifier and TypeMethodDescriptionReturns 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 Details
-
SET_TO_NULL
If a source bean property equalsnullthe target bean property will be set explicitly tonullorOptional.empty()in case the target type is anOptional. -
SET_TO_DEFAULT
If a source bean property equalsnullthe target bean property will be set to its default value.This means:
- For
OptionalMapStruct generates anOptional.empty() - For
ListMapStruct generates anArrayList - For
MapaHashMap - For arrays an empty array
- For
String"" - for primitive / boxed types a representation of
0orfalse - 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
If a source bean property equalsnullthe target bean property will be ignored and retain its existing value. -
CLEAR
If a source bean property equalsnullthe target bean property will be cleared. This strategy is only applicable to target properties that are of typeCollectionorMap.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
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
-