-
Notifications
You must be signed in to change notification settings - Fork 470
Description
Title
Inconsistent JSON link attribute name (“links” vs “_links”) after introducing RestTemplateBuilder configuration
Description
We are maintaining a legacy application that exposes several REST endpoints. The project uses both spring-boot-starter-hateoas and spring-boot-starter-web.
Existing client applications expect the JSON representation of hypermedia links to appear under a field named links. This naming is part of an established API contract we must preserve.
Up to now, our REST endpoints produced responses containing "links": { ... }" — which was the expected behavior.
However, after we introduced a RestTemplate bean created via RestTemplateBuilder, the behavior changed:
- the hypermedia links are now serialized as
"_links"(HAL style) - no other change besides the RestTemplate configuration was made
- this affects the responses of our controllers, not the RestTemplate itself
To preserve the legacy behavior, we attempted:
spring.hateoas.use-hal-as-default-json-media-type: false…but it had no effect.
During debugging we noticed that only when the RestTemplate bean is present the bean HypermediaRestTemplateConfigurer appears in the application context.
This bean seems to activate HAL-style configuration globally, which we did not expect — especially since configuring a RestTemplate should not influence how controller responses are serialized.
What we expected
Configuring a custom RestTemplate should not change the JSON serialization format of the server-side HATEOAS responses.
What actually happened
After adding:
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}our server endpoints start returning HAL-style JSON with "_links" instead of "links".
Minimal Reproducible Example
A minimal project demonstrating the issue is included. It contains two tests:
WithoutRestConfigurationTest→ produces"links"(expected)WithRestConfigurationTest→ produces"_links"(unexpected)
The logs also show that only in the second case HypermediaRestTemplateConfigurer is created.
Minimal reproducible example
https://github.com/Fachher/spring-resttemplate-incident
A quick fix would be to exclude HypermediaAutoConfiguration but this is strange.