diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index cd3e7eab4..4c1434bde 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -105,9 +105,11 @@ public @interface Mapper { CollectionMappingStrategy collectionMappingStrategy() default CollectionMappingStrategy.DEFAULT; /** - * The strategy to be applied when for returning a target when the source equals null. + * The strategy to be applied when {@code null} is passed as source value to the methods of this mapper. If no + * strategy is configured, the strategy given via {@link MapperConfig#nullValueMappingStrategy()} will be applied, + * using {@link NullValueMappingStrategy#RETURN_NULL} by default. * - * @return The strategy applied when determining whether to return null or an empty object, list or map. + * @return The strategy to be applied when {@code null} is passed as source value to the methods of this mapper. */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.DEFAULT; } diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index f120ad546..3341bb3fb 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -83,9 +83,10 @@ public @interface MapperConfig { CollectionMappingStrategy collectionMappingStrategy() default CollectionMappingStrategy.DEFAULT; /** - * The strategy to be applied when for returning a target when the source equals null. + * The strategy to be applied when {@code null} is passed as source value to mapping methods. If no strategy is + * configured, {@link NullValueMappingStrategy#RETURN_NULL} will be used by default. * - * @return The strategy applied when determining whether to return null or an empty object, list or map. + * @return The strategy to be applied when {@code null} is passed as source value to mapping methods. */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.DEFAULT; } diff --git a/core-common/src/main/java/org/mapstruct/NullValueMapping.java b/core-common/src/main/java/org/mapstruct/NullValueMapping.java index ad1e26db4..ad7d88b69 100644 --- a/core-common/src/main/java/org/mapstruct/NullValueMapping.java +++ b/core-common/src/main/java/org/mapstruct/NullValueMapping.java @@ -24,17 +24,10 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Determines what kind to return in case of a null source argument. + * Specifies how the annotated method should deal with {@code null} values. *
- * For: - *
- *
- * When given via {@link NullValueMapping#value() ()}, causes the setting specified via + * When given via {@link NullValueMapping#value()}, causes the setting specified via * {@link Mapper#nullValueMappingStrategy() ()} to be applied, if present. *
* Otherwise causes {@link #RETURN_NULL} to be applied.
diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java
index 897fd76c7..1d7a0dc75 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/mapnulltodefault/CarMapper.java
@@ -18,14 +18,16 @@
*/
package org.mapstruct.ap.test.mapnulltodefault;
+import static org.mapstruct.NullValueMappingStrategy.RETURN_DEFAULT;
+
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.mapstruct.Mapper;
-import org.mapstruct.NullValueMapping;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
+import org.mapstruct.NullValueMapping;
import org.mapstruct.ap.test.mapnulltodefault.source.Car;
import org.mapstruct.ap.test.mapnulltodefault.target.CarDto;
import org.mapstruct.factory.Mappers;
@@ -35,7 +37,7 @@ public interface CarMapper {
CarMapper INSTANCE = Mappers.getMapper( CarMapper.class );
- @NullValueMapping
+ @NullValueMapping(RETURN_DEFAULT)
@Mappings({
@Mapping(target = "seatCount", source = "numberOfSeats"),
@Mapping(target = "model", constant = "ModelT"),
@@ -43,7 +45,7 @@ public interface CarMapper {
})
CarDto carToCarDto(Car car);
- @NullValueMapping
+ @NullValueMapping(RETURN_DEFAULT)
@Mappings({
@Mapping(target = "seatCount", source = "car.numberOfSeats"),
@Mapping(target = "model", source = "model"), // TODO, should not be needed, must be made based on name only
@@ -52,10 +54,9 @@ public interface CarMapper {
CarDto carToCarDto(Car car, String model);
- @NullValueMapping
+ @NullValueMapping(RETURN_DEFAULT)
List