Repository navigation
Consider custom write converters before pinning the column type - #2332
Closed
Develop-KIM wants to merge 1 commit into
Closed
Develop-KIM wants to merge 1 commit into
Develop-KIM wants to merge 1 commit into
Conversation
Registering a user @WritingConverter for a source type, such as Instant -> String, had no effect on write. determineCustomWriteTarget asked whether the source could be written as the target type first, and that target type is pinned to Timestamp for java.time values by JdbcColumnTypes. The store's own Instant -> Timestamp converter satisfied that check, so a user converter registered for the same source type was never consulted and the value was always written as a Timestamp. We now look up a custom write target for the source type before considering the target type pinned by the store, so user converters take precedence. Closes spring-projects#2292 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Donghwan Kim <kimdonghwan913@gmail.com>
Contributor
|
Thanks, that's polished, merged and ported back. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2292.
A user-registered
@WritingConverterfor a source type (e.g.Instant -> String) was ignored on write — the value was always stored as aTimestamp.MappingRelationalConverter.determineCustomWriteTargetfirst asks whether the source can be written as the target type, and forjava.timevalues that target type is pinned toTimestampbyJdbcColumnTypes. The store's ownInstant -> Timestampconverter satisfies that check, so a user converter registered for the same source type is never consulted.This reorders the lookup so a custom write target registered for the source type is considered before the target type pinned by the store — the direction @christophstrobl pointed at on the issue ("checks for custom write targets happen before pinning the target type to
Timestamp").Since a
source -> targetregistration implies asource -> *registration, the previously-first two-arg lookup only ever matched when the source-only lookup would too, so the reorder changes behaviour only for the shadowing case above.Added a unit test in
MappingJdbcConverterUnitTeststhat writes anInstantthrough a userInstant -> Stringconverter and asserts the result is theString, not aTimestamp. The existing converter suites inspring-data-jdbcandspring-data-relationalstay green (theTimestampround-trip tests included).This was prepared with AI assistance (Claude Code) and reviewed by me before submitting.
🤖 Generated with Claude Code