openrewrite / openrewrite/rewrite-spring

[Spring Data MongoDB 5.0] Detect missing explicit value representation configuration

Open
#1,083 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
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-ID BigInteger fields 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 BigInteger IDs.
  • Report all affected fields through the MongoValueRepresentationFields data table.
  • Recognise valid Java configuration and Spring Boot configuration in .properties and YAML, including relaxed spellings, property placeholders, and the legacy spring.data.mongodb.uuid-representation key.
  • When configuration is missing, add the Spring Data MongoDB 4 effective default: java-legacy for UUID values and string for BigDecimal/BigInteger values.
  • Add those defaults to the preferred base application*.properties/.yml/.yaml file, or generate src/main/resources/application.properties when no suitable base configuration file exists.
  • Flag blank, malformed, unsupported, null, or explicitly UNSPECIFIED Java, 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 / BigDecimal persistence 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 explicit UNSPECIFIED configuration 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.