-
Notifications
You must be signed in to change notification settings - Fork 565
Description
spring-hateoas has introduced MediaTypeConfigurationCustomizer
, which can be used to configure/modify HalConfiguration
and HalFormsConfiguration
in an additive way instead of overwriting the whole bean. (see spring-projects/spring-hateoas#2035)
However, these customizers are not applied in spring-data-rest where HalConfiguration
or HalFormsConfiguration
are used (in RepositoryRestMvcConfiguration
), leading to an inconsistency between the configuration as used by spring-hateoas and the one used by spring-data-rest.
I bumped into this because I am using a customizer-based configuration, and its behavior is different when using only spring-hateoas or when having a dependency on spring-data-rest-webmvc (even though it is not being used for this particular endpoint).
@Bean
MediaTypeConfigurationCustomizer<HalConfiguration> halConfigurationCustomizer() {
return halConfiguration -> halConfiguration
.withRenderSingleLinksFor("supplier", RenderSingleLinks.AS_ARRAY);
}
Without spring-data-rest-webmvc, the response looks like expected (the supplier
link is an array, even though only one link item is present)
{
"id":null,
"received":null,
"supplier":null,
"_version":0,
"pay_before":null,
"total_amount":null,
"_links":{
"supplier":[
{"href":"test"}
]
}
}
When adding a dependency on spring-data-rest-webmvc, the 'render single links' customization seems to get ignored, falling back to the default:
{
"received" : null,
"pay_before" : null,
"total_amount" : null,
"_links" : {
"supplier" : {
"href" : "test"
}
}
}
I have an example application displaying the issue here:
invoice-api.zip.
This shows the issue with spring-data-rest-webmvc.
To see the behavior without spring-data-rest-webmvc, either uncomment the exclude line in build.gradle
or remove the whole dependeny on the spring-data-rest starter)