ShapeShift
  • Overview
  • Introduction
    • Installation
    • Quick Start
  • API Documentation
    • Annotations
    • Kotlin DSL
    • Java Builder
  • Features
    • Transformers
    • Auto Mapping
    • Conditions
    • Decorators
    • Object Suppliers
    • Mapping Strategy
  • Guides
    • Implicit Transformers
    • Instance Mapping
    • Advanced Mapping
    • Spring Usage
    • Android Usage
Powered by GitBook
On this page
  • Options
  • Usage
  • Default Mapping Strategy
  • Override Mapping Strategy

Was this helpful?

Export as PDF
  1. Features

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()
ShapeShift shapeShift = new ShapeShiftBuilder()
        .withDefaultMappingStrategy(MappingStrategy.MAP_ALL)
        .build();

Override Mapping Strategy

Overriding the mapping strategy for a specific field.

Annotations

@MappedField(overrideMappingStrategy = MappingStrategy.MAP_ALL)
@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();
PreviousObject SuppliersNextImplicit Transformers

Last updated 2 years ago

Was this helpful?