Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Require explicit representation configuration for UUID, BigDecimal, and BigInteger #5044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HyunSangHan wants to merge 2 commits into spring-projects:main from HyunSangHan:issue/5037

Conversation

Copy link
Contributor

@HyunSangHan HyunSangHan commented Aug 17, 2025
edited
Loading

Remove implicit defaults for UUID, BigDecimal, and BigInteger representations to force explicit configuration.

  • MongoConfigurationSupport: Require explicit UuidRepresentation configuration in mongoClientSettings()
  • MongoClientFactoryBean: Require explicit UuidRepresentation configuration in computeClientSetting()
  • MongoCustomConversions: Require explicit BigDecimalRepresentation configuration (covers both BigDecimal and BigInteger)

Resolves: #5037

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

injae-kim reacted with thumbs up emoji injae-kim reacted with heart emoji injae-kim reacted with rocket emoji
Signed-off-by: Hyunsang Han <gustkd3@gmail.com>
Signed-off-by: Hyunsang Han <gustkd3@gmail.com>
@HyunSangHan HyunSangHan changed the title (削除) Require explicit representation configuration for UUID, BigDecimal, and BigInteger (削除ここまで) (追記) Require explicit representation configuration for UUID, BigDecimal, and BigInteger (追記ここまで) Aug 17, 2025
Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way these changes manifest is that application startup always breaks if uuid/big decimal representations aren't configured. That isn't ideal as users that don't need these features are forced to make a configuration change.

It would be much more appropriate to check whether such types are used at all.

A utility that walks the MongoMappingContext and introspects whether entities have a property that uses UUID, BigDecimal, or BigInteger would be less invasive and more targeted. We clearly cannot capture uuid/big decimal usage that operates solely on Documents (no entity usage) and in these cases, applications would only fail during runtime.


MongoClientSettings settings = builder.build();

if (settings.getUuidRepresentation() == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would break applications for users that do not use UUIDs.

HyunSangHan reacted with thumbs up emoji
Copy link
Contributor Author

@HyunSangHan HyunSangHan Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mp911de

The way these changes manifest is that application startup always breaks if uuid/big decimal representations aren't configured. That isn't ideal as users that don't need these features are forced to make a configuration change.

You're right. I realize I totally went in the wrong direction here.

Thanks for pointing out that forcing configuration for everyone is too invasive. I’ve been thinking this week about how to make the validation smarter, only checking when these types are actually in use.

Here's what I'm considering:

  • Create a TypeUsageValidator class that scans the mapping context to detect which entities actually use BigDecimal/BigInteger/UUID
  • For each type found in use, delegate to validateBigDecimalConfiguration, validateBigIntegerConfiguration, and validateUuidConfiguration to ensure defaults are explicitly configured (If not, throwing an exception.)
  • Run this validation in afterPropertiesSet(), when the mapping context is fully initialized

Does this direction make more sense? If so, I can refine it quickly and reopen the PR. 💪

@@ -375,6 +376,10 @@ ConverterConfiguration createConverterConfiguration() {
svc.init();
}

if (bigDecimals == null) {
throw new IllegalStateException("BigDecimal representation must be explicitly configured.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same breaking behavior as for UUIDs. We would also break applications for users that do not use big decimals.

HyunSangHan reacted with eyes emoji
return builder.build();
MongoClientSettings settings = builder.build();

if (settings.getUuidRepresentation() == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@mp911de mp911de self-assigned this Aug 18, 2025
Copy link
Contributor Author

Apologies for not updating the PR during the past week. I’ll make the necessary improvements and update it within this week.

Copy link
Contributor Author

@mp911de
Oh, I saw your new PR #5051.
Thank you. Then I'll close this PR :)

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

@mp911de mp911de mp911de requested changes

Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Refine representation format defaulting for UUID, BigDecimal, and BigInteger

AltStyle によって変換されたページ (->オリジナル) /