spring-projects / spring-projects/spring-hateoas
Using Java Records as Hal Form Request Body Types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
I try to use Java records as input parameter types for request bodies because I'd like to treat the data as immutable. However, Spring Hateoas does not fully support HAL Forms metadata for this approach.
I can add many of the annotations described at https://docs.spring.io/spring-hateoas/docs/current/reference/html/#mediatypes.hal-forms.metadata to record constructor parameters, but not InputType. I get a compile error '@InputType' not applicable to parameter because of its @Target definition.
I can apply Hibernate's @Length annotation to a record constructor param, but Spring Hateoas does not evaluate it, the HAL Form property is rendered without the length information.
Also, record constructor arguments are rendered as readOnly, although a caller can send them to change those arguments. Maybe an additional @ReadOnly annotation would be in order to tell consumers whether or not a data item may be used to alter the value of this element, if no setter is present.
Bottom line: could we support HAL Forms metadata Java records just like classes?
Contributor guide
No contributing guide indexed for this repository
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
Start with the HAL Forms metadata entry point and compare how annotations on ordinary class properties are evaluated with annotations on Java record constructor parameters. Check the existing metadata behavior for InputType, validation length, and read-only status; done means records expose equivalent HAL Forms metadata or the issue's required limitations are clearly resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100