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
1c4f1f0e
Commit
1c4f1f0e
authored
Nov 18, 2014
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jackson-mapper'
parents
cea47bd4
b8d6b340
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
9 deletions
+42
-9
JacksonAutoConfiguration.java
.../boot/autoconfigure/jackson/JacksonAutoConfiguration.java
+2
-1
HttpMapperProperties.java
...ramework/boot/autoconfigure/web/HttpMapperProperties.java
+7
-6
HttpMessageConvertersAutoConfiguration.java
...configure/web/HttpMessageConvertersAutoConfiguration.java
+6
-2
HttpMessageConvertersAutoConfigurationTests.java
...gure/web/HttpMessageConvertersAutoConfigurationTests.java
+27
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java
View file @
1c4f1f0e
...
@@ -109,7 +109,8 @@ public class JacksonAutoConfiguration {
...
@@ -109,7 +109,8 @@ public class JacksonAutoConfiguration {
@ConditionalOnMissingBean
(
Jackson2ObjectMapperBuilder
.
class
)
@ConditionalOnMissingBean
(
Jackson2ObjectMapperBuilder
.
class
)
public
Jackson2ObjectMapperBuilder
jacksonObjectMapperBuilder
()
{
public
Jackson2ObjectMapperBuilder
jacksonObjectMapperBuilder
()
{
Jackson2ObjectMapperBuilder
builder
=
new
Jackson2ObjectMapperBuilder
();
Jackson2ObjectMapperBuilder
builder
=
new
Jackson2ObjectMapperBuilder
();
if
(
this
.
httpMapperProperties
.
isJsonSortKeys
())
{
Boolean
isJsonSortKeys
=
this
.
httpMapperProperties
.
isJsonSortKeys
();
if
(
isJsonSortKeys
!=
null
&&
isJsonSortKeys
)
{
builder
.
featuresToEnable
(
SerializationFeature
.
ORDER_MAP_ENTRIES_BY_KEYS
);
builder
.
featuresToEnable
(
SerializationFeature
.
ORDER_MAP_ENTRIES_BY_KEYS
);
}
}
configureFeatures
(
builder
,
this
.
jacksonProperties
.
getDeserialization
());
configureFeatures
(
builder
,
this
.
jacksonProperties
.
getDeserialization
());
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMapperProperties.java
View file @
1c4f1f0e
...
@@ -24,27 +24,28 @@ import org.springframework.http.converter.HttpMessageConverter;
...
@@ -24,27 +24,28 @@ import org.springframework.http.converter.HttpMessageConverter;
*
*
* @author Dave Syer
* @author Dave Syer
* @author Piotr Maj
* @author Piotr Maj
* @author Sebastien Deleuze
*/
*/
@ConfigurationProperties
(
prefix
=
"http.mappers"
,
ignoreUnknownFields
=
false
)
@ConfigurationProperties
(
prefix
=
"http.mappers"
,
ignoreUnknownFields
=
false
)
public
class
HttpMapperProperties
{
public
class
HttpMapperProperties
{
private
b
oolean
jsonPrettyPrint
;
private
B
oolean
jsonPrettyPrint
;
private
b
oolean
jsonSortKeys
;
private
B
oolean
jsonSortKeys
;
public
void
setJsonPrettyPrint
(
b
oolean
jsonPrettyPrint
)
{
public
void
setJsonPrettyPrint
(
B
oolean
jsonPrettyPrint
)
{
this
.
jsonPrettyPrint
=
jsonPrettyPrint
;
this
.
jsonPrettyPrint
=
jsonPrettyPrint
;
}
}
public
b
oolean
isJsonPrettyPrint
()
{
public
B
oolean
isJsonPrettyPrint
()
{
return
this
.
jsonPrettyPrint
;
return
this
.
jsonPrettyPrint
;
}
}
public
void
setJsonSortKeys
(
b
oolean
jsonSortKeys
)
{
public
void
setJsonSortKeys
(
B
oolean
jsonSortKeys
)
{
this
.
jsonSortKeys
=
jsonSortKeys
;
this
.
jsonSortKeys
=
jsonSortKeys
;
}
}
public
b
oolean
isJsonSortKeys
()
{
public
B
oolean
isJsonSortKeys
()
{
return
this
.
jsonSortKeys
;
return
this
.
jsonSortKeys
;
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java
View file @
1c4f1f0e
...
@@ -78,7 +78,9 @@ public class HttpMessageConvertersAutoConfiguration {
...
@@ -78,7 +78,9 @@ public class HttpMessageConvertersAutoConfiguration {
ObjectMapper
objectMapper
)
{
ObjectMapper
objectMapper
)
{
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
();
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
();
converter
.
setObjectMapper
(
objectMapper
);
converter
.
setObjectMapper
(
objectMapper
);
converter
.
setPrettyPrint
(
this
.
properties
.
isJsonPrettyPrint
());
if
(
this
.
properties
.
isJsonPrettyPrint
()
!=
null
)
{
converter
.
setPrettyPrint
(
this
.
properties
.
isJsonPrettyPrint
());
}
return
converter
;
return
converter
;
}
}
...
@@ -99,7 +101,9 @@ public class HttpMessageConvertersAutoConfiguration {
...
@@ -99,7 +101,9 @@ public class HttpMessageConvertersAutoConfiguration {
Jackson2ObjectMapperBuilder
builder
)
{
Jackson2ObjectMapperBuilder
builder
)
{
MappingJackson2XmlHttpMessageConverter
converter
=
new
MappingJackson2XmlHttpMessageConverter
();
MappingJackson2XmlHttpMessageConverter
converter
=
new
MappingJackson2XmlHttpMessageConverter
();
converter
.
setObjectMapper
(
builder
.
createXmlMapper
(
true
).
build
());
converter
.
setObjectMapper
(
builder
.
createXmlMapper
(
true
).
build
());
converter
.
setPrettyPrint
(
this
.
properties
.
isJsonPrettyPrint
());
if
(
this
.
properties
.
isJsonPrettyPrint
()
!=
null
)
{
converter
.
setPrettyPrint
(
this
.
properties
.
isJsonPrettyPrint
());
}
return
converter
;
return
converter
;
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfigurationTests.java
View file @
1c4f1f0e
...
@@ -21,6 +21,8 @@ import java.util.List;
...
@@ -21,6 +21,8 @@ import java.util.List;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -34,6 +36,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
...
@@ -34,6 +36,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
/**
...
@@ -155,6 +158,30 @@ public class HttpMessageConvertersAutoConfigurationTests {
...
@@ -155,6 +158,30 @@ public class HttpMessageConvertersAutoConfigurationTests {
assertConverterBeanRegisteredWithHttpMessageConverters
(
StringHttpMessageConverter
.
class
);
assertConverterBeanRegisteredWithHttpMessageConverters
(
StringHttpMessageConverter
.
class
);
}
}
@Test
public
void
httpMapperPropertiesAreNotAppliedWhenNotConfigured
()
throws
Exception
{
this
.
context
.
register
(
JacksonObjectMapperConfig
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
);
this
.
context
.
refresh
();
MappingJackson2HttpMessageConverter
converter
=
this
.
context
.
getBean
(
MappingJackson2HttpMessageConverter
.
class
);
assertNull
(
new
DirectFieldAccessor
(
converter
)
.
getPropertyValue
(
"prettyPrint"
));
}
@Test
public
void
httpMapperPropertiesAreAppliedWhenConfigured
()
throws
Exception
{
this
.
context
.
register
(
JacksonObjectMapperConfig
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"http.mappers.jsonPrettyPrint:true"
);
this
.
context
.
refresh
();
MappingJackson2HttpMessageConverter
converter
=
this
.
context
.
getBean
(
MappingJackson2HttpMessageConverter
.
class
);
assertTrue
((
Boolean
)
new
DirectFieldAccessor
(
converter
)
.
getPropertyValue
(
"prettyPrint"
));
}
private
void
assertConverterBeanExists
(
Class
<?>
type
,
String
beanName
)
{
private
void
assertConverterBeanExists
(
Class
<?>
type
,
String
beanName
)
{
assertEquals
(
1
,
this
.
context
.
getBeansOfType
(
type
).
size
());
assertEquals
(
1
,
this
.
context
.
getBeansOfType
(
type
).
size
());
List
<
String
>
beanNames
=
Arrays
.
asList
(
this
.
context
.
getBeanDefinitionNames
());
List
<
String
>
beanNames
=
Arrays
.
asList
(
this
.
context
.
getBeanDefinitionNames
());
...
...
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