# 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();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shapeshift.krud.dev/features/mapping-strategy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
