Mapping Strategy
Mapping behavior for null values.
Use the mapping strategy to define basic mapping behavior for
null
values.The following options are available for mapping strategy:
- MAP_ALL - A strategy that maps all values of a field.
- MAP_NOT_NULL - A strategy that maps only the values of a field that are not null. If the field value is null it will not override the current value in the target class instance. This is the default strategy when creating a new ShapeShift instance.
There are two options for setting the mapping strategy:
Settings the default mapping strategy for the ShapeShift instance.
Kotlin
Java
val shapeShift = ShapeShiftBuilder()
.withDefaultMappingStrategy(MappingStrategy.MAP_ALL)
.build()
ShapeShift shapeShift = new ShapeShiftBuilder()
.withDefaultMappingStrategy(MappingStrategy.MAP_ALL)
.build();
Overriding the mapping strategy for a specific field.
Kotlin
Java
@MappedField(overrideMappingStrategy = MappingStrategy.MAP_ALL)
@MappedField(overrideMappingStrategy = MappingStrategy.MAP_ALL)
val mapper = mapper<From, To> {
From::value mappedTo To::value overrideStrategy MappingStrategy.MAP_NOT_NULL
}
MappingDefinition mappingDefinition = new MappingDefinitionBuilder(From.class, To.class)
.mapField("value", "value").withMappingStrategy(MappingStrategy.MAP_NOT_NULL)
.build();
Last modified 1yr ago