Support resolution of HAL link titles from a resource bundle

Spring HATEOAS 0.19.0.RELEASE provide support for resolving a link’s
title by looking up the key _links.$rel.title. For us to take advantage
of this in Spring Boot, HalHandlerInstantiator must be created using
the link relation message source that’s automatically created by
HateoasConfiguration.

Closes gh-3860
pull/3799/head
Andy Wilkinson 9 years ago
parent 378ce1280a
commit be640965a6

@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.hateoas.EntityLinks; import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.LinkDiscoverers; import org.springframework.hateoas.LinkDiscoverers;
import org.springframework.hateoas.RelProvider; import org.springframework.hateoas.RelProvider;
@ -89,6 +90,10 @@ public class HypermediaAutoConfiguration {
@Autowired(required = false) @Autowired(required = false)
private ObjectMapper primaryObjectMapper; private ObjectMapper primaryObjectMapper;
@Autowired
@Qualifier("linkRelationMessageSource")
private MessageSourceAccessor linkRelationMessageSource;
@PostConstruct @PostConstruct
public void configurePrimaryObjectMapper() { public void configurePrimaryObjectMapper() {
if (this.primaryObjectMapper != null if (this.primaryObjectMapper != null
@ -101,7 +106,8 @@ public class HypermediaAutoConfiguration {
objectMapper.registerModule(new Jackson2HalModule()); objectMapper.registerModule(new Jackson2HalModule());
Jackson2HalModule.HalHandlerInstantiator instantiator = new Jackson2HalModule.HalHandlerInstantiator( Jackson2HalModule.HalHandlerInstantiator instantiator = new Jackson2HalModule.HalHandlerInstantiator(
HalObjectMapperConfiguration.this.relProvider, HalObjectMapperConfiguration.this.relProvider,
HalObjectMapperConfiguration.this.curieProvider, null); HalObjectMapperConfiguration.this.curieProvider,
this.linkRelationMessageSource);
objectMapper.setHandlerInstantiator(instantiator); objectMapper.setHandlerInstantiator(instantiator);
} }

Loading…
Cancel
Save