1313
1414import org .mapstruct .ap .internal .prism .BeanMappingPrism ;
1515import org .mapstruct .ap .internal .prism .BuilderPrism ;
16+ import org .mapstruct .ap .internal .prism .NullValueCheckStrategyPrism ;
1617import org .mapstruct .ap .internal .prism .NullValueMappingStrategyPrism ;
1718import org .mapstruct .ap .internal .prism .ReportingPolicyPrism ;
1819import org .mapstruct .ap .internal .util .FormattingMessager ;
@@ -27,6 +28,7 @@ public class BeanMapping {
2728
2829 private final SelectionParameters selectionParameters ;
2930 private final NullValueMappingStrategyPrism nullValueMappingStrategy ;
31+ private final NullValueCheckStrategyPrism nullValueCheckStrategy ;
3032 private final ReportingPolicyPrism reportingPolicy ;
3133 private final boolean ignoreByDefault ;
3234 private final List <String > ignoreUnmappedSourceProperties ;
@@ -42,6 +44,7 @@ public static BeanMapping forInheritance( BeanMapping map ) {
4244 return new BeanMapping (
4345 map .selectionParameters ,
4446 map .nullValueMappingStrategy ,
47+ map .nullValueCheckStrategy ,
4548 map .reportingPolicy ,
4649 false ,
4750 map .ignoreUnmappedSourceProperties ,
@@ -63,6 +66,11 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem
6366 ? null
6467 : NullValueMappingStrategyPrism .valueOf ( beanMapping .nullValueMappingStrategy () );
6568
69+ NullValueCheckStrategyPrism nullValueCheckStrategy =
70+ null == beanMapping .values .nullValueCheckStrategy ()
71+ ? null
72+ : NullValueCheckStrategyPrism .valueOf ( beanMapping .nullValueCheckStrategy () );
73+
6674 boolean ignoreByDefault = beanMapping .ignoreByDefault ();
6775 BuilderPrism builderMapping = null ;
6876 if ( beanMapping .values .builder () != null ) {
@@ -71,7 +79,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem
7179
7280 if ( !resultTypeIsDefined && beanMapping .qualifiedBy ().isEmpty () && beanMapping .qualifiedByName ().isEmpty ()
7381 && beanMapping .ignoreUnmappedSourceProperties ().isEmpty ()
74- && ( nullValueMappingStrategy == null ) && !ignoreByDefault
82+ && ( nullValueMappingStrategy == null ) && ( nullValueCheckStrategy == null ) && !ignoreByDefault
7583 && builderMapping == null ) {
7684
7785 messager .printMessage ( method , Message .BEANMAPPING_NO_ELEMENTS );
@@ -88,6 +96,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem
8896 return new BeanMapping (
8997 cmp ,
9098 nullValueMappingStrategy ,
99+ nullValueCheckStrategy ,
91100 null ,
92101 ignoreByDefault ,
93102 beanMapping .ignoreUnmappedSourceProperties (),
@@ -102,14 +111,24 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem
102111 * @return bean mapping that needs to be used for Mappings
103112 */
104113 public static BeanMapping forForgedMethods () {
105- return new BeanMapping ( null , null , ReportingPolicyPrism .IGNORE , false , Collections .<String >emptyList (), null );
114+ return new BeanMapping (
115+ null ,
116+ null ,
117+ null ,
118+ ReportingPolicyPrism .IGNORE ,
119+ false ,
120+ Collections .<String >emptyList (),
121+ null
122+ );
106123 }
107124
108125 private BeanMapping (SelectionParameters selectionParameters , NullValueMappingStrategyPrism nvms ,
126+ NullValueCheckStrategyPrism nvcs ,
109127 ReportingPolicyPrism reportingPolicy , boolean ignoreByDefault ,
110- List <String > ignoreUnmappedSourceProperties , BuilderPrism builder ) {
128+ List <String > ignoreUnmappedSourceProperties , BuilderPrism builder ) {
111129 this .selectionParameters = selectionParameters ;
112130 this .nullValueMappingStrategy = nvms ;
131+ this .nullValueCheckStrategy = nvcs ;
113132 this .reportingPolicy = reportingPolicy ;
114133 this .ignoreByDefault = ignoreByDefault ;
115134 this .ignoreUnmappedSourceProperties = ignoreUnmappedSourceProperties ;
@@ -124,6 +143,10 @@ public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
124143 return nullValueMappingStrategy ;
125144 }
126145
146+ public NullValueCheckStrategyPrism getNullValueCheckStrategy () {
147+ return nullValueCheckStrategy ;
148+ }
149+
127150 public ReportingPolicyPrism getReportingPolicy () {
128151 return reportingPolicy ;
129152 }
0 commit comments