> For the complete documentation index, see [llms.txt](https://shapeshift.krud.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shapeshift.krud.dev/features/mapping-strategy.md).

# Mapping Strategy

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.

{% tabs %}
{% tab title="Kotlin" %}

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

{% endtab %}

{% tab title="Java" %}

```java
ShapeShift shapeShift = new ShapeShiftBuilder()
        .withDefaultMappingStrategy(MappingStrategy.MAP_ALL)
        .build();
```

{% endtab %}
{% endtabs %}

### Override Mapping Strategy

Overriding the mapping strategy for a specific field.

#### Annotations

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
@MappedField(overrideMappingStrategy = MappingStrategy.MAP_ALL)
```

{% endtab %}

{% tab title="Java" %}

```java
@MappedField(overrideMappingStrategy = MappingStrategy.MAP_ALL)
```

{% endtab %}
{% endtabs %}

#### Kotlin DSL

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

#### Java Builder

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