openrewrite / openrewrite/rewrite-spring
[Spring Data MongoDB 5.0] Detect missing explicit value representation configuration
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 403
- Forks
- 149
- Avg merge
- 2h 33m
- Merged PRs (30d)
- 10
Description
Parent tracking issue
- #1081
Prerequisite
- #1082 provides the Spring Data MongoDB 5 migration composite.
Problem
Spring Data MongoDB 5 no longer provides default representations for persisted UUID, BigInteger, and BigDecimal values. Applications persisting these types must explicitly configure the corresponding representation rather than relying on earlier defaults.
Spring Data MongoDB 4 did have effective defaults for previously unconfigured applications:
- UUID:
JAVA_LEGACY - BigDecimal / BigInteger:
STRING
The migration must preserve that existing behavior by making those defaults explicit. Existing explicit configuration must not be silently replaced; malformed, null, unsupported, or explicitly UNSPECIFIED values remain diagnostic because the intended representation cannot be inferred safely from source alone.
Implemented solution
PR #1098 adds FindMissingMongoValueRepresentation, a project-scoped diagnostic recipe, and AddMongoValueRepresentationProperty, a mutation recipe, that:
- Detect explicitly MongoDB-mapped
UUID,BigDecimal, and non-IDBigIntegerfields requiring an explicit representation, including nested collection and map-value types. - Exclude irrelevant fields such as non-Mongo domain fields, transient/static fields, explicitly targeted numeric fields, map keys, and
BigIntegerIDs. - Report all affected fields through the
MongoValueRepresentationFieldsdata table. - Recognise valid Java configuration and Spring Boot configuration in
.propertiesand YAML, including relaxed spellings, property placeholders, and the legacyspring.data.mongodb.uuid-representationkey. - When configuration is missing, add the Spring Data MongoDB 4 effective default:
java-legacyfor UUID values andstringfor BigDecimal/BigInteger values. - Add those defaults to the preferred base
application*.properties/.yml/.yamlfile, or generatesrc/main/resources/application.propertieswhen no suitable base configuration file exists. - Flag blank, malformed, unsupported,
null, or explicitlyUNSPECIFIEDJava, properties, and YAML configuration in place without overwriting it. - Ignore test-source configuration when evaluating main-source persistence and continue to diagnose invalid profile overrides even when another configuration file contains a valid default.
- Avoid duplicate properties, comments, and data-table rows across recipe cycles and separate invocations.
- Compose both recipes into
UpgradeSpringDataMongoDb_5_0.
Out of scope
- Inferring a representation different from the Spring Data MongoDB 4 default from existing stored BSON data.
- Rewriting existing MongoDB data.
- MongoDB dependency alignment; see #1082.
- Listener-container behaviour or removed JMX support.
- General Spring Boot property migration already handled by generated Boot property recipes.
Acceptance criteria
- UUID persistence usage is detected when no explicit UUID representation is configured.
-
BigInteger/BigDecimalpersistence usage is detected when no explicit numeric representation is configured. - Existing supported Java, properties, and YAML configuration suppresses the corresponding diagnostic/default insertion.
- Missing UUID configuration receives the Spring Data MongoDB 4 default
java-legacy. - Missing BigDecimal/BigInteger configuration receives the Spring Data MongoDB 4 default
string. - A baseline configuration file is generated when required.
- Invalid, blank, malformed,
null, and explicitUNSPECIFIEDconfiguration is diagnosed in place and not silently overwritten. - Tests cover configured, unconfigured, profile-specific, nested-value, generated-file, invalid-configuration, cross-project, composite, and idempotent cases.
- The recipes are composed into the Spring Data MongoDB 5 migration composite.
References
- Spring Data MongoDB 4.x to 5.x migration guide: https://docs.spring.io/spring-data/mongodb/reference/migration-guide/migration-guide-4.x-to-5.x.html
- Spring Boot 4.0 migration guide: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review PR #1098 and the named entry points FindMissingMongoValueRepresentation, AddMongoValueRepresentationProperty, and UpgradeSpringDataMongoDb_5_0. Compare their behavior with the acceptance criteria, especially configuration detection, generated files, invalid values, nested types, cross-project handling, and idempotence; done means the listed tests and migration composition are complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mongodb, spring, spring-boot
- Domain
- databases, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 15/100