Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
fb3deab8
Commit
fb3deab8
authored
Nov 27, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
971adfcd
e81abc3f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
CodecsAutoConfiguration.java
...oot/autoconfigure/http/codec/CodecsAutoConfiguration.java
+1
-0
CodecsAutoConfigurationTests.java
...utoconfigure/http/codec/CodecsAutoConfigurationTests.java
+72
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfiguration.java
View file @
fb3deab8
...
@@ -54,6 +54,7 @@ public class CodecsAutoConfiguration {
...
@@ -54,6 +54,7 @@ public class CodecsAutoConfiguration {
static
class
JacksonCodecConfiguration
{
static
class
JacksonCodecConfiguration
{
@Bean
@Bean
@Order
(
0
)
@ConditionalOnBean
(
ObjectMapper
.
class
)
@ConditionalOnBean
(
ObjectMapper
.
class
)
public
CodecCustomizer
jacksonCodecCustomizer
(
ObjectMapper
objectMapper
)
{
public
CodecCustomizer
jacksonCodecCustomizer
(
ObjectMapper
objectMapper
)
{
return
(
configurer
)
->
{
return
(
configurer
)
->
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfigurationTests.java
View file @
fb3deab8
...
@@ -16,13 +16,17 @@
...
@@ -16,13 +16,17 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
http
.
codec
;
package
org
.
springframework
.
boot
.
autoconfigure
.
http
.
codec
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.http.HttpProperties
;
import
org.springframework.boot.autoconfigure.http.HttpProperties
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.annotation.AnnotationAwareOrderComparator
;
import
org.springframework.core.annotation.AnnotationAwareOrderComparator
;
import
org.springframework.http.codec.CodecConfigurer
;
import
org.springframework.http.codec.CodecConfigurer
;
import
org.springframework.http.codec.support.DefaultClientCodecConfigurer
;
import
org.springframework.http.codec.support.DefaultClientCodecConfigurer
;
...
@@ -34,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -34,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link CodecsAutoConfiguration}.
* Tests for {@link CodecsAutoConfiguration}.
*
*
* @author Madhura Bhave
* @author Madhura Bhave
* @author Andy Wilkinson
*/
*/
public
class
CodecsAutoConfigurationTests
{
public
class
CodecsAutoConfigurationTests
{
...
@@ -76,6 +81,30 @@ public class CodecsAutoConfigurationTests {
...
@@ -76,6 +81,30 @@ public class CodecsAutoConfigurationTests {
});
});
}
}
@Test
public
void
jacksonCodecCustomizerBacksOffWhenThereIsNoObjectMapper
()
{
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
)
.
doesNotHaveBean
(
"jacksonCodecCustomizer"
));
}
@Test
public
void
jacksonCodecCustomizerIsAutoConfiguredWhenObjectMapperIsPresent
()
{
this
.
contextRunner
.
withUserConfiguration
(
ObjectMapperConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasBean
(
"jacksonCodecCustomizer"
));
}
@Test
public
void
userProvidedCustomizerCanOverrideJacksonCodecCustomizer
()
{
this
.
contextRunner
.
withUserConfiguration
(
ObjectMapperConfiguration
.
class
,
CodecCustomizerConfiguration
.
class
).
run
((
context
)
->
{
List
<
CodecCustomizer
>
codecCustomizers
=
context
.
getBean
(
CodecCustomizers
.
class
).
codecCustomizers
;
assertThat
(
codecCustomizers
).
hasSize
(
3
);
assertThat
(
codecCustomizers
.
get
(
2
))
.
isInstanceOf
(
TestCodecCustomizer
.
class
);
});
}
static
class
TestAnnotationAwareOrderComparator
static
class
TestAnnotationAwareOrderComparator
extends
AnnotationAwareOrderComparator
{
extends
AnnotationAwareOrderComparator
{
...
@@ -86,4 +115,47 @@ public class CodecsAutoConfigurationTests {
...
@@ -86,4 +115,47 @@ public class CodecsAutoConfigurationTests {
}
}
@Configuration
static
class
ObjectMapperConfiguration
{
@Bean
ObjectMapper
objectMapper
()
{
return
new
ObjectMapper
();
}
}
@Configuration
static
class
CodecCustomizerConfiguration
{
@Bean
CodecCustomizer
codecCustomizer
()
{
return
new
TestCodecCustomizer
();
}
@Bean
CodecCustomizers
codecCustomizers
(
List
<
CodecCustomizer
>
customizers
)
{
return
new
CodecCustomizers
(
customizers
);
}
}
private
static
final
class
TestCodecCustomizer
implements
CodecCustomizer
{
@Override
public
void
customize
(
CodecConfigurer
configurer
)
{
}
}
private
static
final
class
CodecCustomizers
{
private
final
List
<
CodecCustomizer
>
codecCustomizers
;
private
CodecCustomizers
(
List
<
CodecCustomizer
>
codecCustomizers
)
{
this
.
codecCustomizers
=
codecCustomizers
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment