Skip to content

#3997 Fix InheritInverseConfiguration ignore for nested sources with parameter prefix#4091

Open
kamilkrzywanski wants to merge 1 commit into
mapstruct:mainfrom
kamilkrzywanski:issue-3997-inherit-inverse-ignore-parameter-prefix
Open

#3997 Fix InheritInverseConfiguration ignore for nested sources with parameter prefix#4091
kamilkrzywanski wants to merge 1 commit into
mapstruct:mainfrom
kamilkrzywanski:issue-3997-inherit-inverse-ignore-parameter-prefix

Conversation

@kamilkrzywanski

Copy link
Copy Markdown

Summary

Fixes #3997

When a forward mapping uses a source path that includes the source parameter name (e.g. source.client.id), @InheritInverseConfiguration previously kept that prefix in the inverse target name (source.client.id). As a result, @Mapping(target = "client", ignore = true) on the inverse method did not match the nested inherited mapping, and MapStruct still created intermediate objects for ignored properties.

Root cause

  1. copyForInverseInheritance swapped source/target naively, so source = "source.client.id" became inverse target = "source.client.id".
  2. Code generation later strips the parameter prefix via TargetReference, so nested mapping still worked.
  3. Ignore / redefinition matching runs earlier on the raw target name, where the first segment is the parameter name (source), not the property (client).

Fix

When building the inverse target name, strip the source parameter name prefix (e.g. source.client.idclient.id), mirroring SourceReference / TargetReference resolution. If the first segment is also a property of the source type, the full path is kept (property path takes precedence).

Tests

  • Reproducer from the issue: nested sources with parameter prefix + inverse ignore = true → nested properties stay null
  • Guard: same nested sources without ignores still reverse-map correctly

Checklist

  • Provide test cases
  • One pull request per feature/bug
  • Meaningful history (single focused commit)
  • Changelog entry in NEXT_RELEASE_CHANGELOG.md

…ces with parameter prefix

When a forward mapping uses a source path that includes the source parameter
name (e.g. source.client.id), inverse inheritance previously kept that prefix
in the inverse target name. Ignore and redefinition matching then failed
because the first path segment was the parameter name rather than the property.

Strip the source parameter name prefix when building the inverse target name,
mirroring SourceReference / TargetReference resolution.
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.

@InheritInverseConfiguration ignores "ignore = true" for nested source fields

1 participant