Skip to content

Convert auditor values to property types - #3577

Closed
2748109647 wants to merge 1 commit into
spring-projects:mainfrom
2748109647:codex/gh-3437-auditor-conversion
Closed

2748109647 wants to merge 1 commit into
spring-projects:mainfrom
2748109647:codex/gh-3437-auditor-conversion

Conversation

@2748109647

Copy link
Copy Markdown

What this changes

@CreatedBy and @LastModifiedBy values are currently assigned as-is. When one AuditorAware supplies a value for entities whose auditor properties use different types, assignment can fail even when Spring's existing wrapper ConversionService supports the conversion.

This converts auditor values to each annotated property type in reflection-only and MappingContext-based wrappers. It reuses the wrapper's existing ConversionService and leaves Auditable interface implementations unchanged.

Closes #3437

Verification

  • .\mvnw.cmd -Dtest=AuditorConversionUnitTests test — passed (2 tests).
  • .\mvnw.cmd '-Dtest=AuditorConversionUnitTests,ReflectionAuditingBeanWrapperUnitTests,MappingAuditableBeanWrapperFactoryUnitTests,DefaultAuditableBeanWrapperFactoryUnitTests,AuditingHandlerUnitTests' test — passed (45 tests).
  • git diff --check — passed.

Use the existing wrapper ConversionService when setting auditor values on reflection- and mapping-based properties. Keep Auditable interface implementations unchanged.

Closes spring-projects#3437

Signed-off-by: Alpha <2748109647@qq.com>
@christophstrobl

Copy link
Copy Markdown
Member

Thank you for looking into this issue and providing a PR.

While we do think this change solves a certain problem we do not think it would be a good fit in general, as it replaces strict checking with implicit conversions that may produce incorrect/corrupted values.
A conversion that is technically supported must not necessarily be a vaild one. The conversion service may also invoke constructors, factory methods, finders and therefore lead to unexpected behavior.

We prefer to stick to the current loud assignment failures for incompatible types. A potential enhancement might go in the direction of opt in (maybe templated) conversion with dedicated extension points.

@christophstrobl christophstrobl added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auditing: ConversionService support for CreatedBy/LastUpdatedBy

3 participants