@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.http ;
import java.nio.charset.StandardCharsets ;
import javax.json.bind.Jsonb ;
import com.fasterxml.jackson.databind.ObjectMapper ;
@ -28,6 +30,7 @@ import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration.MappingJackson2HttpMessageConverterConfiguration ;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration ;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration ;
import org.springframework.boot.autoconfigure.web.ServerProperties ;
import org.springframework.boot.test.context.FilteredClassLoader ;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
@ -237,6 +240,38 @@ class HttpMessageConvertersAutoConfigurationTests {
. run ( ( context ) - > assertThat ( context ) . doesNotHaveBean ( HttpMessageConverters . class ) ) ;
}
@Test
void whenEncodingCharsetIsNotConfiguredThenStringMessageConverterUsesUtf8 ( ) {
new WebApplicationContextRunner ( )
. withConfiguration ( AutoConfigurations . of ( HttpMessageConvertersAutoConfiguration . class ) )
. run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( StringHttpMessageConverter . class ) ;
assertThat ( context . getBean ( StringHttpMessageConverter . class ) . getDefaultCharset ( ) )
. isEqualTo ( StandardCharsets . UTF_8 ) ;
} ) ;
}
@Test
void whenEncodingCharsetIsConfiguredThenStringMessageConverterUsesSpecificCharset ( ) {
new WebApplicationContextRunner ( )
. withConfiguration ( AutoConfigurations . of ( HttpMessageConvertersAutoConfiguration . class ) )
. withPropertyValues ( "server.servlet.encoding.charset=UTF-16" ) . run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( StringHttpMessageConverter . class ) ;
assertThat ( context . getBean ( StringHttpMessageConverter . class ) . getDefaultCharset ( ) )
. isEqualTo ( StandardCharsets . UTF_16 ) ;
} ) ;
}
@Test // gh-21789
void whenAutoConfigurationIsActiveThenServerPropertiesConfigurationPropertiesAreNotEnabled ( ) {
new WebApplicationContextRunner ( )
. withConfiguration ( AutoConfigurations . of ( HttpMessageConvertersAutoConfiguration . class ) )
. run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( HttpMessageConverters . class ) ;
assertThat ( context ) . doesNotHaveBean ( ServerProperties . class ) ;
} ) ;
}
private ApplicationContextRunner allOptionsRunner ( ) {
return this . contextRunner . withConfiguration ( AutoConfigurations . of ( GsonAutoConfiguration . class ,
JacksonAutoConfiguration . class , JsonbAutoConfiguration . class ) ) ;