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:
{ "_templates": { "default": { "properties": [ { "name": "foo" }, { "name": "bar" } ] } } }We want to be able to assign a default value
helloto attributefooin theHAL-FORMSpayload to obtain something like this:{ "_templates": { "default": { "properties": [ { "name": "foo", "value": "hello" }, { "name": "bar" } ] } } }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 typeStringas output.Considered alternatives
Retrieve the value directly from the payload instance
To do that, this kind of consumer code would be needed:
baris verified for non-nullity inPayloadconstructor.On the 2nd point, some may argue that
jakarta.validation.constraints.NotNullshould be used instead of the in-house constructor validation. On that my opinion is as follow:@NotNullshould be avoided when plain simple java code is able to enforce the same constraintnullvalue assigned to a@NotNullproperty, 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.