|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2017 the original author or authors.
|
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -18,11 +18,6 @@ package org.springframework.boot.autoconfigure.hateoas;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeansException;
|
|
|
|
|
import org.springframework.beans.factory.BeanFactory;
|
|
|
|
|
import org.springframework.beans.factory.BeanFactoryAware;
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
@ -33,7 +28,6 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
|
|
|
|
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.Import;
|
|
|
|
|
import org.springframework.hateoas.EntityLinks;
|
|
|
|
@ -42,7 +36,6 @@ import org.springframework.hateoas.Resource;
|
|
|
|
|
import org.springframework.hateoas.config.EnableEntityLinks;
|
|
|
|
|
import org.springframework.hateoas.config.EnableHypermediaSupport;
|
|
|
|
|
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
|
|
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
|
|
|
import org.springframework.plugin.core.Plugin;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
|
@ -71,11 +64,6 @@ public class HypermediaAutoConfiguration {
|
|
|
|
|
@EnableHypermediaSupport(type = HypermediaType.HAL)
|
|
|
|
|
protected static class HypermediaConfiguration {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public static HalObjectMapperConfigurer halObjectMapperConfigurer() {
|
|
|
|
|
return new HalObjectMapperConfigurer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@ -85,46 +73,4 @@ public class HypermediaAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@link BeanPostProcessor} to apply any {@link Jackson2ObjectMapperBuilder}
|
|
|
|
|
* configuration to the HAL {@link ObjectMapper}.
|
|
|
|
|
*/
|
|
|
|
|
private static class HalObjectMapperConfigurer
|
|
|
|
|
implements BeanPostProcessor, BeanFactoryAware {
|
|
|
|
|
|
|
|
|
|
private BeanFactory beanFactory;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
|
|
|
|
throws BeansException {
|
|
|
|
|
if (bean instanceof ObjectMapper && "_halObjectMapper".equals(beanName)) {
|
|
|
|
|
postProcessHalObjectMapper((ObjectMapper) bean);
|
|
|
|
|
}
|
|
|
|
|
return bean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void postProcessHalObjectMapper(ObjectMapper objectMapper) {
|
|
|
|
|
try {
|
|
|
|
|
Jackson2ObjectMapperBuilder builder = this.beanFactory
|
|
|
|
|
.getBean(Jackson2ObjectMapperBuilder.class);
|
|
|
|
|
builder.configure(objectMapper);
|
|
|
|
|
}
|
|
|
|
|
catch (NoSuchBeanDefinitionException ex) {
|
|
|
|
|
// No Jackson configuration required
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName)
|
|
|
|
|
throws BeansException {
|
|
|
|
|
return bean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
|
|
|
|
this.beanFactory = beanFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|