Skip to content

Using Java Records as Hal Form Request Body Types #2494

@dschulten

Description

@dschulten

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions