diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java index 1383c41d31..0b3d3483c7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 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. @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.data.rest; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -30,6 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; /** * {@link EnableAutoConfiguration Auto-configuration} for Spring Data Rest's MVC @@ -56,8 +58,9 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio public class RepositoryRestMvcAutoConfiguration { @Bean - public SpringBootRepositoryRestConfigurer springBootRepositoryRestConfigurer() { - return new SpringBootRepositoryRestConfigurer(); + public SpringBootRepositoryRestConfigurer springBootRepositoryRestConfigurer( + ObjectProvider objectMapperBuilder, RepositoryRestProperties properties) { + return new SpringBootRepositoryRestConfigurer(objectMapperBuilder.getIfAvailable(), properties); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java index 45b925c62d..ac0d8732cc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -38,10 +38,16 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry; class SpringBootRepositoryRestConfigurer implements RepositoryRestConfigurer { @Autowired(required = false) - private Jackson2ObjectMapperBuilder objectMapperBuilder; + private final Jackson2ObjectMapperBuilder objectMapperBuilder; @Autowired - private RepositoryRestProperties properties; + private final RepositoryRestProperties properties; + + SpringBootRepositoryRestConfigurer(Jackson2ObjectMapperBuilder objectMapperBuilder, + RepositoryRestProperties properties) { + this.objectMapperBuilder = objectMapperBuilder; + this.properties = properties; + } @Override @SuppressWarnings("deprecation")