Support for HAL-FORMS value element #2039
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1717
Behaviour before this change
Let be:
Calling GET will return something like:
We want to be able to assign a default value
hello
to attributefoo
in theHAL-FORMS
payload to obtain something like this:Solution brought by this change
The implemented solution is heavily inspired from
HalFormsOptionsFactory
. A consumer can provide a value creator, taking a property metadata as input and returning a value of typeString
as output.Considered alternatives
Retrieve the value directly from the payload instance
To do that, this kind of consumer code would be needed:
bar
is verified for non-nullity inPayload
constructor.On the 2nd point, some may argue that
jakarta.validation.constraints.NotNull
should be used instead of the in-house constructor validation. On that my opinion is as follow:@NotNull
should be avoided when plain simple java code is able to enforce the same constraintnull
value assigned to a@NotNull
property, at worst will fail the compilationRetrieve the value from a new annotation on the considered property
This would force the consumer to know the value before compilation.