Skip to content

Commit 1ab98ca

Browse files
wilkinsonasnicoll
authored andcommitted
Start building against Spring HATEOAS 0.25.0 snapshots
See gh-13742
1 parent 21160da commit 1ab98ca

File tree

3 files changed

+6
-76
lines changed

3 files changed

+6
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,11 +18,6 @@
1818

1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020

21-
import org.springframework.beans.BeansException;
22-
import org.springframework.beans.factory.BeanFactory;
23-
import org.springframework.beans.factory.BeanFactoryAware;
24-
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
25-
import org.springframework.beans.factory.config.BeanPostProcessor;
2621
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2722
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2823
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -33,7 +28,6 @@
3328
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
3429
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
3530
import org.springframework.boot.context.properties.EnableConfigurationProperties;
36-
import org.springframework.context.annotation.Bean;
3731
import org.springframework.context.annotation.Configuration;
3832
import org.springframework.context.annotation.Import;
3933
import org.springframework.hateoas.EntityLinks;
@@ -42,7 +36,6 @@
4236
import org.springframework.hateoas.config.EnableEntityLinks;
4337
import org.springframework.hateoas.config.EnableHypermediaSupport;
4438
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
45-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
4639
import org.springframework.plugin.core.Plugin;
4740
import org.springframework.web.bind.annotation.RequestMapping;
4841

@@ -71,11 +64,6 @@ public class HypermediaAutoConfiguration {
7164
@EnableHypermediaSupport(type = HypermediaType.HAL)
7265
protected static class HypermediaConfiguration {
7366

74-
@Bean
75-
public static HalObjectMapperConfigurer halObjectMapperConfigurer() {
76-
return new HalObjectMapperConfigurer();
77-
}
78-
7967
}
8068

8169
@Configuration
@@ -85,46 +73,4 @@ protected static class EntityLinksConfiguration {
8573

8674
}
8775

88-
/**
89-
* {@link BeanPostProcessor} to apply any {@link Jackson2ObjectMapperBuilder}
90-
* configuration to the HAL {@link ObjectMapper}.
91-
*/
92-
private static class HalObjectMapperConfigurer
93-
implements BeanPostProcessor, BeanFactoryAware {
94-
95-
private BeanFactory beanFactory;
96-
97-
@Override
98-
public Object postProcessBeforeInitialization(Object bean, String beanName)
99-
throws BeansException {
100-
if (bean instanceof ObjectMapper && "_halObjectMapper".equals(beanName)) {
101-
postProcessHalObjectMapper((ObjectMapper) bean);
102-
}
103-
return bean;
104-
}
105-
106-
private void postProcessHalObjectMapper(ObjectMapper objectMapper) {
107-
try {
108-
Jackson2ObjectMapperBuilder builder = this.beanFactory
109-
.getBean(Jackson2ObjectMapperBuilder.class);
110-
builder.configure(objectMapper);
111-
}
112-
catch (NoSuchBeanDefinitionException ex) {
113-
// No Jackson configuration required
114-
}
115-
}
116-
117-
@Override
118-
public Object postProcessAfterInitialization(Object bean, String beanName)
119-
throws BeansException {
120-
return bean;
121-
}
122-
123-
@Override
124-
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
125-
this.beanFactory = beanFactory;
126-
}
127-
128-
}
129-
13076
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package org.springframework.boot.autoconfigure.hateoas;
1818

19-
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import com.fasterxml.jackson.databind.SerializationFeature;
2119
import org.junit.After;
2220
import org.junit.Test;
2321

2422
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
23+
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration.EntityLinksConfiguration;
24+
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration.HypermediaConfiguration;
2525
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
2626
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
2727
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
@@ -91,24 +91,8 @@ public void doesBackOffIfEnableHypermediaSupportIsDeclaredManually() {
9191
TestPropertyValues.of("spring.jackson.serialization.INDENT_OUTPUT:true")
9292
.applyTo(this.context);
9393
this.context.refresh();
94-
ObjectMapper objectMapper = this.context.getBean("_halObjectMapper",
95-
ObjectMapper.class);
96-
assertThat(objectMapper.getSerializationConfig()
97-
.isEnabled(SerializationFeature.INDENT_OUTPUT)).isFalse();
98-
}
99-
100-
@Test
101-
public void jacksonConfigurationIsAppliedToTheHalObjectMapper() {
102-
this.context = new AnnotationConfigWebApplicationContext();
103-
this.context.setServletContext(new MockServletContext());
104-
this.context.register(BaseConfig.class);
105-
TestPropertyValues.of("spring.jackson.serialization.INDENT_OUTPUT:true")
106-
.applyTo(this.context);
107-
this.context.refresh();
108-
ObjectMapper objectMapper = this.context.getBean("_halObjectMapper",
109-
ObjectMapper.class);
110-
assertThat(objectMapper.getSerializationConfig()
111-
.isEnabled(SerializationFeature.INDENT_OUTPUT)).isTrue();
94+
assertThat(this.context.getBeansOfType(HypermediaConfiguration.class)).isEmpty();
95+
assertThat(this.context.getBeansOfType(EntityLinksConfiguration.class)).isEmpty();
11296
}
11397

11498
@Test

spring-boot-project/spring-boot-dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
<spring-batch.version>4.0.1.RELEASE</spring-batch.version>
157157
<spring-cloud-connectors.version>2.0.2.RELEASE</spring-cloud-connectors.version>
158158
<spring-data-releasetrain.version>Kay-SR8</spring-data-releasetrain.version>
159-
<spring-hateoas.version>0.24.0.RELEASE</spring-hateoas.version>
159+
<spring-hateoas.version>0.25.0.BUILD-SNAPSHOT</spring-hateoas.version>
160160
<spring-integration.version>5.0.7.BUILD-SNAPSHOT</spring-integration.version>
161161
<spring-kafka.version>2.1.8.BUILD-SNAPSHOT</spring-kafka.version>
162162
<spring-ldap.version>2.3.2.RELEASE</spring-ldap.version>

0 commit comments

Comments
 (0)