Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HyunSangHan
Copy link
Contributor

@HyunSangHan HyunSangHan commented Aug 17, 2025

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).

@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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label 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.

@@ -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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine representation format defaulting for UUID, BigDecimal, and BigInteger
3 participants