Package org.mapstruct

Enum NullValueMappingStrategy

java.lang.Object
java.lang.Enum<NullValueMappingStrategy>
org.mapstruct.NullValueMappingStrategy
All Implemented Interfaces:
Serializable, Comparable<NullValueMappingStrategy>, java.lang.constant.Constable

public enum NullValueMappingStrategy extends Enum<NullValueMappingStrategy>
Strategy for dealing with null values passed to mapping methods.
Author:
Sjaak Derksen
  • Enum Constant Details

    • RETURN_NULL

      public static final NullValueMappingStrategy RETURN_NULL
      If null is passed to a mapping method, null will be returned, unless the return type is Optional, in which case an empty optional will be returned. That's the default behavior if no alternative strategy is configured globally, for given mapper or method.
    • RETURN_DEFAULT

      public static final NullValueMappingStrategy RETURN_DEFAULT
      If null is passed to a mapping method, a default value will be returned. The value depends on the kind of the annotated method:
      • For bean mapping methods the target type will be instantiated and returned. Any properties of the target type which are mapped via Mapping.expression() or Mapping.constant() will be populated based on the given expression or constant. Note that expressions must be prepared to deal with null values in this case.
      • For iterable mapping methods an empty collection will be returned.
      • For map mapping methods an empty map will be returned.
      • For optional mapping methods an empty optional will be returned.
  • Method Details

    • values

      public static NullValueMappingStrategy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static NullValueMappingStrategy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null