Skip to content

#2436 Apply defaultValue/defaultExpression when a source parameter is null#4014

Open
dlwldnjs1009 wants to merge 1 commit intomapstruct:mainfrom
dlwldnjs1009:fix/2436-default-value-null-source-parameter
Open

#2436 Apply defaultValue/defaultExpression when a source parameter is null#4014
dlwldnjs1009 wants to merge 1 commit intomapstruct:mainfrom
dlwldnjs1009:fix/2436-default-value-null-source-parameter

Conversation

@dlwldnjs1009
Copy link
Copy Markdown

When a source parameter itself is null in a multi-source mapping, or in a single-source mapping with RETURN_DEFAULT, the generated code now applies defaultValue / defaultExpression instead of skipping those assignments.

The root cause was that the parameter-level presence checks in BeanMappingMethod.ftl had no fallback branch. If the source parameter was null, the whole block was skipped, including any configured defaults.

This change adds fallback handling for the parameter-level presence check branches in BeanMappingMethod.ftl, and adds isBuiltInPresenceCheckByParameter() in BeanMappingMethod.java so that custom @SourceParameterCondition methods keep their existing behavior.

The _913 fixtures are updated as well. Only the create path changes here; update / updateWithReturn stay unchanged because they are guarded by existingInstanceMapping.

Tests cover:

  • multi-source mappings with either source parameter null
  • constructor mappings
  • single-source RETURN_DEFAULT
  • single-source constructor RETURN_DEFAULT
  • @SourceParameterCondition true/false behavior
  • the unchanged all-sources-null early return

Closes #2436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With multiple source parameters, allow using defaultValue when a source parameter is null

1 participant