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
8a55fbeb
Commit
8a55fbeb
authored
Jan 31, 2014
by
Christian Dupuis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow pretty printed JSON output (nicer for demos and easier to read)
Defaults to false
parent
3911ce3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
HttpMessageConvertersAutoConfiguration.java
...configure/web/HttpMessageConvertersAutoConfiguration.java
+25
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java
View file @
8a55fbeb
...
...
@@ -29,6 +29,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
...
...
@@ -42,6 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* {@link EnableAutoConfiguration Auto-configuration} for {@link HttpMessageConverter}s.
*
* @author Dave Syer
* @author Christian Dupuis
*/
@Configuration
@ConditionalOnClass
(
HttpMessageConverter
.
class
)
...
...
@@ -60,8 +63,12 @@ public class HttpMessageConvertersAutoConfiguration {
@Configuration
@ConditionalOnClass
(
ObjectMapper
.
class
)
@EnableConfigurationProperties
(
ObjectMappersProperties
.
class
)
protected
static
class
ObjectMappers
{
@Autowired
private
ObjectMappersProperties
properties
=
new
ObjectMappersProperties
();
@Autowired
private
ListableBeanFactory
beanFactory
;
...
...
@@ -90,9 +97,27 @@ public class HttpMessageConvertersAutoConfiguration {
ObjectMapper
objectMapper
)
{
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
();
converter
.
setObjectMapper
(
objectMapper
);
converter
.
setPrettyPrint
(
this
.
properties
.
isJsonPrettyPrint
());
return
converter
;
}
}
/**
* {@link ConfigurationProperties} to configure {@link HttpMessageConverter}s.
*/
@ConfigurationProperties
(
name
=
"http.mappers"
,
ignoreUnknownFields
=
false
)
public
static
class
ObjectMappersProperties
{
private
boolean
jsonPrettyPrint
=
false
;
public
void
setJsonPrettyPrint
(
boolean
jsonPrettyPrint
)
{
this
.
jsonPrettyPrint
=
jsonPrettyPrint
;
}
public
boolean
isJsonPrettyPrint
()
{
return
this
.
jsonPrettyPrint
;
}
}
}
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