public enum NullValuePropertyMappingStrategy extends Enum<NullValuePropertyMappingStrategy>
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
overide 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.
Enum Constant and Description |
---|
IGNORE
If a source bean property equals
null the target bean property will be ignored and retain its
existing value. |
SET_TO_DEFAULT
If a source bean property equals
null the target bean property will be set to its default value. |
SET_TO_NULL
If a source bean property equals
null the target bean property will be set explicitly to null . |
Modifier and Type | Method and 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.
|
public static final NullValuePropertyMappingStrategy SET_TO_NULL
null
the target bean property will be set explicitly to null
.public static final NullValuePropertyMappingStrategy SET_TO_DEFAULT
null
the target bean property will be set to its default value.
This means:
List
MapStruct generates an ArrayList
Map
a HashMap
String
""
0
or false
Make sure that a Mapping.defaultValue()
is defined if no empty constructor is available on
the default value.
public static final NullValuePropertyMappingStrategy IGNORE
null
the target bean property will be ignored and retain its
existing value.public static NullValuePropertyMappingStrategy[] values()
for (NullValuePropertyMappingStrategy c : NullValuePropertyMappingStrategy.values()) System.out.println(c);
public static NullValuePropertyMappingStrategy valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullCopyright © 2012-2021 MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.