Skip to content

Consider custom write converters before pinning the column type - #2332

Closed
Develop-KIM wants to merge 1 commit into
spring-projects:mainfrom
Develop-KIM:issue/2292
Closed

Develop-KIM wants to merge 1 commit into
spring-projects:mainfrom
Develop-KIM:issue/2292

Conversation

@Develop-KIM

Copy link
Copy Markdown
Contributor

Fixes #2292.

A user-registered @WritingConverter for a source type (e.g. Instant -> String) was ignored on write — the value was always stored as a Timestamp.

MappingRelationalConverter.determineCustomWriteTarget first asks whether the source can be written as the target type, and for java.time values that target type is pinned to Timestamp by JdbcColumnTypes. The store's own Instant -> Timestamp converter 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 -> target registration implies a source -> * 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 MappingJdbcConverterUnitTests that writes an Instant through a user Instant -> String converter and asserts the result is the String, not a Timestamp. The existing converter suites in spring-data-jdbc and spring-data-relational stay green (the Timestamp round-trip tests included).

This was prepared with AI assistance (Claude Code) and reviewed by me before submitting.

🤖 Generated with Claude Code

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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 24, 2026
schauder pushed a commit that referenced this pull request Aug 5, 2026
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 #2292
Original pull request #2332

Signed-off-by: Donghwan Kim <kimdonghwan913@gmail.com>
schauder added a commit that referenced this pull request Aug 5, 2026
Replace class in test with record.
Remove superfluous comment.
Formatting.

See #2292
Original pull request #2332
schauder pushed a commit that referenced this pull request Aug 5, 2026
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 #2292
Original pull request #2332

Signed-off-by: Donghwan Kim <kimdonghwan913@gmail.com>
schauder added a commit that referenced this pull request Aug 5, 2026
Replace class in test with record.
Remove superfluous comment.
Formatting.

See #2292
Original pull request #2332
schauder pushed a commit that referenced this pull request Aug 5, 2026
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 #2292
Original pull request #2332

Signed-off-by: Donghwan Kim <kimdonghwan913@gmail.com>
schauder added a commit that referenced this pull request Aug 5, 2026
Replace class in test with record.
Remove superfluous comment.
Formatting.

See #2292
Original pull request #2332
@schauder

schauder commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Thanks, that's polished, merged and ported back.

@schauder schauder closed this Aug 5, 2026
@schauder schauder added this to the 4.0.7 (2025.1.7) milestone Aug 5, 2026
@schauder schauder self-assigned this Aug 5, 2026
@schauder schauder added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jsr310TimestampBasedConverters cannot be overriden via user converters in JdbcCustomConversions

3 participants