Start building against Spring HATEOAS 0.25.0 snapshots

See gh-13742
pull/13211/merge
Andy Wilkinson 6 years ago
parent 8426e3c2c9
commit cf3b1f6653

@ -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;
}
}
}

@ -16,12 +16,12 @@
package org.springframework.boot.autoconfigure.hateoas;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration.EntityLinksConfiguration;
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration.HypermediaConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
@ -91,24 +91,8 @@ public class HypermediaAutoConfigurationTests {
TestPropertyValues.of("spring.jackson.serialization.INDENT_OUTPUT:true")
.applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context.getBean("_halObjectMapper",
ObjectMapper.class);
assertThat(objectMapper.getSerializationConfig()
.isEnabled(SerializationFeature.INDENT_OUTPUT)).isFalse();
}
@Test
public void jacksonConfigurationIsAppliedToTheHalObjectMapper() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
TestPropertyValues.of("spring.jackson.serialization.INDENT_OUTPUT:true")
.applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context.getBean("_halObjectMapper",
ObjectMapper.class);
assertThat(objectMapper.getSerializationConfig()
.isEnabled(SerializationFeature.INDENT_OUTPUT)).isTrue();
assertThat(this.context.getBeansOfType(HypermediaConfiguration.class)).isEmpty();
assertThat(this.context.getBeansOfType(EntityLinksConfiguration.class)).isEmpty();
}
@Test

@ -156,7 +156,7 @@
<spring-batch.version>4.0.1.RELEASE</spring-batch.version>
<spring-cloud-connectors.version>2.0.2.RELEASE</spring-cloud-connectors.version>
<spring-data-releasetrain.version>Lovelace-BUILD-SNAPSHOT</spring-data-releasetrain.version>
<spring-hateoas.version>0.24.0.RELEASE</spring-hateoas.version>
<spring-hateoas.version>0.25.0.BUILD-SNAPSHOT</spring-hateoas.version>
<spring-integration.version>5.0.6.RELEASE</spring-integration.version>
<spring-kafka.version>2.2.0.BUILD-SNAPSHOT</spring-kafka.version>
<spring-ldap.version>2.3.2.RELEASE</spring-ldap.version>

Loading…
Cancel
Save