-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Expected behavior
MapStruct generates a null-check that considers only non-primitive method parameters. When all non-primitive arguments are null, the generated mapper method returns null early, even if primitive parameters contain valid values.
As a result, mappings for primitive (or boxed-with-default) arguments are skipped entirely.
Expected behavior
If primitive parameters (e.g. int, boolean) have valid values, MapStruct should still map them to the target object, even when all non-primitive parameters are null.
At minimum, primitive arguments should not be ignored solely because non-primitive arguments are null.
Actual behavior
MapStruct generates an early return null when all non-primitive parameters are null, causing primitive argument mappings to be ignored.
Example
Mapper method:
Target map(
String sku,
String name,
Long categoryId,
int size,
int pageNumber,
boolean draft
);
Generated logic (simplified):
if (sku == null && name == null && categoryId == null) {
return null;
}
target.setSize(size);
target.setPageNumber(pageNumber);
target.setDraft(draft);
In this case:
- sku, name, and categoryId are null
- size, pageNumber, and draft have valid values
However, the method returns null, and primitive fields are never mapped.
Impact
- This behavior makes it impossible to create partially populated target objects when:
- all reference-type parameters are null
- primitive parameters still carry meaningful values (e.g. pagination, flags)
- This is especially problematic for search/filter DTOs.
Workaround
- Convert primitive parameters to wrapper types (Integer, Boolean)
- Or manually implement mapping logic instead of relying on generated code
Actual behavior
No response
Steps to reproduce the problem
I have told in description
MapStruct Version
1.6.3