Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
reda-alaoui opened this issue Nov 10, 2023 · 1 comment

Comments

@reda-alaoui
Copy link
Contributor

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.

@odrotbohm
Copy link
Member

odrotbohm commented Nov 13, 2023

Nothing in the current HalFormsConfiguration is designed for extension, as it's impossible to do that without knowing what folks might envision to customize. Can you elaborate on what you're actually trying to achieve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants