All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapstruct.NullValuePropertyMappingStrategy Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
/*
 * Copyright MapStruct Authors.
 *
 * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package org.mapstruct;

/**
 * Strategy for dealing with {@code null} or not present properties in the source bean. The
 * {@link NullValuePropertyMappingStrategy} can be defined on {@link MapperConfig}, {@link Mapper}, {@link BeanMapping}
 * and {@link Mapping}.
 * Precedence is arranged  in the reverse order. So {@link Mapping} will override {@link BeanMapping}, will
 * overide {@link Mapper}
 *
 * The enum only applies to update methods: methods that update a pre-existing target (annotated with
 * {@code @}{@link MappingTarget}).
 *
 *  

* Note: some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder * as target accessor see {@link CollectionMappingStrategy}, MapStruct will always generate a source property * null check, regardless the value of the {@link NullValuePropertyMappingStrategy} to avoid addition of {@code null} * to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied. * * @author Sjaak Derksen * @since 1.3 */ public enum NullValuePropertyMappingStrategy { /** * If a source bean property equals {@code null} the target bean property will be set explicitly to {@code null}. */ SET_TO_NULL, /** * If a source bean property equals {@code null} the target bean property will be set to its default value. *

* This means: *

    *
  1. For {@code List} MapStruct generates an {@code ArrayList}
  2. *
  3. For {@code Map} a {@code HashMap}
  4. *
  5. For arrays an empty array
  6. *
  7. For {@code String} {@code ""}
  8. *
  9. for primitive / boxed types a representation of {@code 0} or {@code false}
  10. *
  11. For all other objects an new instance is created, requiring an empty constructor.
  12. *
*

* Make sure that a {@link Mapping#defaultValue()} is defined if no empty constructor is available on * the default value. */ SET_TO_DEFAULT, /** * If a source bean property equals {@code null} the target bean property will be ignored and retain its * existing value. */ IGNORE; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy