Mapping Strategy

Mapping behavior for null values.

Use the mapping strategy to define basic mapping behavior for null values.

Options

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.

Usage

There are two options for setting the mapping strategy:

Default Mapping Strategy

Settings the default mapping strategy for the ShapeShift instance.

val shapeShift = ShapeShiftBuilder()
    .withDefaultMappingStrategy(MappingStrategy.MAP_ALL)
    .build()

Override Mapping Strategy

Overriding the mapping strategy for a specific field.

Annotations

@MappedField(overrideMappingStrategy = MappingStrategy.MAP_ALL)

Kotlin DSL

val mapper = mapper<From, To> {
    From::value mappedTo To::value overrideStrategy MappingStrategy.MAP_NOT_NULL
}

Java Builder

MappingDefinition mappingDefinition = new MappingDefinitionBuilder(From.class, To.class)
        .mapField("value", "value").withMappingStrategy(MappingStrategy.MAP_NOT_NULL)
        .build();

Last updated