[Java][Spring] useRecords: records as parameter objects
Fourth step towards #10490. With useRecords, query objects become records; list or map elements and objects with a renamed, nullable, untyped or defaulted nested model or container stay classes, with everything below. Renamed scalars get @BindParam, so ?my-name=x binds; unlike the class, ?limit= gives the default and ?name.x=1 on a String is 500. A large query object binds slower than the class until spring-projects/spring-framework#37536.
@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim
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.
Summary by cubic
With useRecords, query parameter objects are now generated as Java records, with @BindParam on renamed scalar components so documented names like ?sort-order=x still bind. Models that Spring's data binder cannot fill as records stay classes, and everything nested below them stays a class too.
- Parameter objects stay classes when they contain a renamed model or container, a nullable or untyped component, a container without an initial value, or a model with a default; list and map elements of a parameter object and models nested in them also stay classes.
- Models converted from one string (header, cookie, path, array items, map values) and members of a
oneOf/anyOfquery parameter remain classes. - The same schema used as a query object and a request body is a record in both roles; the
@BindParamannotation does not affect Jackson binding.