Skip to content

HalFormsConfiguration#withOptions is based on a property name depending on an non obvious internal algorithm #2040

Open
@reda-alaoui

Description

@reda-alaoui

I'd like to customize HalFormsConfiguration in order to be able to produce HAL-Forms options for some template payload properties via a home made annotation based engine.

My goal is to have something like this:

record Payload(@HalFormsPropertyMetadata(optionsFactory = MyOptionsFactory.class) String foo) {

}

class MyOptionsFactory implements OptionsFactory {
  @Override
  Optional<HalFormsOptions> createOptions(AffordanceModel.PropertyMetadata property) {
    return Optional.empty();
  }
}

public interface OptionsFactory {
  Optional<HalFormsOptions> createOptions(AffordanceModel.PropertyMetadata property);
}

To do that, I need to invoke

public <T> HalFormsConfiguration withOptions(Class<T> type, String property,
Function<PropertyMetadata, HalFormsOptions> creator) {

The property argument should be the name of the property for which we try to provide options. But this value is computed like this:

public String getName() {
MergedAnnotation<JsonProperty> annotation = property.getAnnotation(JsonProperty.class);
if (!annotation.isPresent()) {
return property.getName();
}
String annotatedName = annotation.getString("value");
return StringUtils.hasText(annotatedName) ? annotatedName.trim() : property.getName();
}

Since this computation is private, I have no other way than copying the Spring HATEOAS name computation code in my project to make sure to match my annotated property with the name expected by Spring HATEOAS.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions