fix(java): handle formatted values in inner enum comparisons
Description
Fixes #20952.
Formatted inner enums such as type: string, format: uri can generate equalsIgnoreCase() calls on non-String Java values, causing compilation errors when useEnumCaseInsensitive=true.
This change updates 11 affected inner-enum templates to compare formatted string enum values using toString() when useEnumCaseInsensitive=true. Unformatted strings retain their existing behavior, and comparisons with the option disabled remain unchanged.
Null inputs are handled without calling toString() on them. Existing equality behavior is preserved for non-string enums and when useEnumCaseInsensitive=false.
Testing
All 26 parameterized cases pass across 13 generator/library configurations, with case-insensitive matching enabled and disabled.
Tests compile and execute generated fromValue methods in isolated enum fixtures, covering:
- Plain strings, email, and custom string formats.
- URI and UUID values.
- Unformatted and formatted numeric enums.
- Exact matches and differently cased inputs.
- Nullable and non-nullable enums, including distinguishing Java
nullfrom the literal string"null".
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) @KannaKim (2026/07)
Summary by cubic
Fixes #20952. Inner enum comparisons for string formats like uri no longer generate equalsIgnoreCase() calls on non-String values, so Java code using useEnumCaseInsensitive=true compiles.
- Updates 11 inner-enum templates to use
java.util.Objects.equals()when a format is present. - Unformatted string enums keep case-insensitive matching.
- Formatted string enums mapped to Java
Stringnow match case-sensitively. - Adds parameterized regression tests that compile and run generated
fromValuemethods across 13 generator/library configurations.