From 1ab98ca33f953c979d4bba8c93e6476616f2796a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 10 Jul 2018 15:05:22 +0100 Subject: [PATCH] Start building against Spring HATEOAS 0.25.0 snapshots See gh-13742 --- .../hateoas/HypermediaAutoConfiguration.java | 56 +------------------ .../HypermediaAutoConfigurationTests.java | 24 ++------ .../spring-boot-dependencies/pom.xml | 2 +- 3 files changed, 6 insertions(+), 76 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java index 3847ad5ec2..a35993fef1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java @@ -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; - } - - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java index e25fd2af10..3ee320ebe2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java @@ -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 diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index b11d53bd1e..664e0507f0 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -156,7 +156,7 @@ 4.0.1.RELEASE 2.0.2.RELEASE Kay-SR8 - 0.24.0.RELEASE + 0.25.0.BUILD-SNAPSHOT 5.0.7.BUILD-SNAPSHOT 2.1.8.BUILD-SNAPSHOT 2.3.2.RELEASE