@ -16,18 +16,22 @@
@@ -16,18 +16,22 @@
package org.springframework.boot.http.codec.autoconfigure ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import org.jspecify.annotations.Nullable ;
import tools.jackson.databind.ObjectMapper ;
import tools.jackson.databind.json.JsonMapper ;
import org.springframework.boot.autoconfigure.AutoConfiguration ;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration ;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty ;
import org.springframework.boot.context.properties.EnableConfigurationProperties ;
import org.springframework.boot.context.properties.PropertyMapper ;
import org.springframework.boot.http.codec.CodecCustomizer ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Conditional ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.core.Ordered ;
import org.springframework.core.annotation.Order ;
@ -43,14 +47,17 @@ import org.springframework.web.reactive.function.client.WebClient;
@@ -43,14 +47,17 @@ import org.springframework.web.reactive.function.client.WebClient;
* { @link org . springframework . core . codec . Decoder Decoders } .
*
* @author Brian Clozel
* @since 2 . 0 . 0
* @since 4 . 0 . 0
* /
@AutoConfiguration ( afterName = "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration" )
@AutoConfiguration ( afterName = { "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration" ,
"org.springframework.boot.jackson2.autoconfigure.Jackson2AutoConfiguration" } )
@ConditionalOnClass ( { CodecConfigurer . class , WebClient . class } )
public final class CodecsAutoConfiguration {
@Configuration ( proxyBeanMethods = false )
@ConditionalOnClass ( ObjectMapper . class )
@ConditionalOnClass ( JsonMapper . class )
@ConditionalOnProperty ( name = "spring.http.codecs.preferred-json-mapper" , havingValue = "jackson" ,
matchIfMissing = true )
static class JacksonJsonCodecConfiguration {
@Bean
@ -66,6 +73,26 @@ public final class CodecsAutoConfiguration {
@@ -66,6 +73,26 @@ public final class CodecsAutoConfiguration {
}
@Configuration ( proxyBeanMethods = false )
@ConditionalOnClass ( ObjectMapper . class )
@Conditional ( NoJacksonOrJackson2Preferred . class )
@Deprecated ( since = "4.0.0" , forRemoval = true )
@SuppressWarnings ( "removal" )
static class Jackson2JsonCodecConfiguration {
@Bean
@Order ( 0 )
@ConditionalOnBean ( ObjectMapper . class )
CodecCustomizer jackson2CodecCustomizer ( ObjectMapper objectMapper ) {
return ( configurer ) - > {
CodecConfigurer . DefaultCodecs defaults = configurer . defaultCodecs ( ) ;
defaults . jacksonJsonDecoder ( new org . springframework . http . codec . json . Jackson2JsonDecoder ( objectMapper ) ) ;
defaults . jacksonJsonEncoder ( new org . springframework . http . codec . json . Jackson2JsonEncoder ( objectMapper ) ) ;
} ;
}
}
@Configuration ( proxyBeanMethods = false )
@EnableConfigurationProperties ( HttpCodecsProperties . class )
static class DefaultCodecsConfiguration {
@ -104,4 +131,22 @@ public final class CodecsAutoConfiguration {
@@ -104,4 +131,22 @@ public final class CodecsAutoConfiguration {
}
static class NoJacksonOrJackson2Preferred extends AnyNestedCondition {
NoJacksonOrJackson2Preferred ( ) {
super ( ConfigurationPhase . PARSE_CONFIGURATION ) ;
}
@ConditionalOnMissingClass ( "tools.jackson.databind.json.JsonMapper" )
static class NoJackson {
}
@ConditionalOnProperty ( name = "spring.http.codecs.preferred-json-mapper" , havingValue = "jackson2" )
static class Jackson2Preferred {
}
}
}