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
99de71bf
Commit
99de71bf
authored
Mar 18, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade to Jackson 2.5.1
Closes gh-2332
parent
11a1bc93
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
49 deletions
+25
-49
JacksonAutoConfiguration.java
.../boot/autoconfigure/jackson/JacksonAutoConfiguration.java
+6
-6
JacksonAutoConfigurationTests.java
.../autoconfigure/jackson/JacksonAutoConfigurationTests.java
+18
-42
pom.xml
spring-boot-dependencies/pom.xml
+1
-1
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java
View file @
99de71bf
...
...
@@ -52,8 +52,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.datatype.joda.cfg.JacksonJodaDateFormat
;
import
com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer
;
import
com.fasterxml.jackson.datatype.joda.ser.JacksonJodaFormat
;
/**
* Auto configuration for Jackson. The following auto-configuration will get applied:
...
...
@@ -106,7 +106,7 @@ public class JacksonAutoConfiguration {
@Configuration
@ConditionalOnClass
({
Jackson2ObjectMapperBuilder
.
class
,
DateTime
.
class
,
DateTimeSerializer
.
class
,
JacksonJodaFormat
.
class
})
DateTimeSerializer
.
class
,
JacksonJoda
Date
Format
.
class
})
static
class
JodaDateTimeJacksonConfiguration
{
private
final
Log
log
=
LogFactory
.
getLog
(
JodaDateTimeJacksonConfiguration
.
class
);
...
...
@@ -117,7 +117,7 @@ public class JacksonAutoConfiguration {
@Bean
public
Module
jodaDateTimeSerializationModule
()
{
SimpleModule
module
=
new
SimpleModule
();
JacksonJoda
Format
jacksonJodaFormat
=
getJacksonJoda
Format
();
JacksonJoda
DateFormat
jacksonJodaFormat
=
getJacksonJodaDate
Format
();
if
(
jacksonJodaFormat
!=
null
)
{
module
.
addSerializer
(
DateTime
.
class
,
new
DateTimeSerializer
(
jacksonJodaFormat
));
...
...
@@ -125,14 +125,14 @@ public class JacksonAutoConfiguration {
return
module
;
}
private
JacksonJoda
Format
getJacksonJoda
Format
()
{
private
JacksonJoda
DateFormat
getJacksonJodaDate
Format
()
{
if
(
this
.
jacksonProperties
.
getJodaDateTimeFormat
()
!=
null
)
{
return
new
JacksonJodaFormat
(
DateTimeFormat
.
forPattern
(
return
new
JacksonJoda
Date
Format
(
DateTimeFormat
.
forPattern
(
this
.
jacksonProperties
.
getJodaDateTimeFormat
()).
withZoneUTC
());
}
if
(
this
.
jacksonProperties
.
getDateFormat
()
!=
null
)
{
try
{
return
new
JacksonJodaFormat
(
DateTimeFormat
.
forPattern
(
return
new
JacksonJoda
Date
Format
(
DateTimeFormat
.
forPattern
(
this
.
jacksonProperties
.
getDateFormat
()).
withZoneUTC
());
}
catch
(
IllegalArgumentException
ex
)
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java
View file @
99de71bf
...
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jackson
;
import
java.io.IOException
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashSet
;
...
...
@@ -45,12 +46,17 @@ import com.fasterxml.jackson.databind.JsonSerializer;
import
com.fasterxml.jackson.databind.MapperFeature
;
import
com.fasterxml.jackson.databind.Module
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.util.StdDateFormat
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasItem
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
...
...
@@ -124,8 +130,7 @@ public class JacksonAutoConfigurationTests {
this
.
context
.
register
(
JacksonAutoConfiguration
.
class
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
();
assertEquals
(
String
.
valueOf
(
date
.
getTime
()),
mapper
.
writeValueAsString
(
date
));
assertThat
(
mapper
.
getDateFormat
(),
is
(
instanceOf
(
StdDateFormat
.
class
)));
}
@Test
...
...
@@ -135,11 +140,10 @@ public class JacksonAutoConfigurationTests {
"spring.jackson.date-format:yyyyMMddHHmmss"
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
DateTime
dateTime
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
,
DateTimeZone
.
UTC
);
assertEquals
(
"\"19880625203000\""
,
mapper
.
writeValueAsString
(
dateTime
));
dateTime
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
);
Date
date
=
dateTime
.
toDate
();
assertEquals
(
"\"19880625203000\""
,
mapper
.
writeValueAsString
(
date
));
DateFormat
dateFormat
=
mapper
.
getDateFormat
();
assertThat
(
dateFormat
,
is
(
instanceOf
(
SimpleDateFormat
.
class
)));
assertThat
(((
SimpleDateFormat
)
dateFormat
).
toPattern
(),
is
(
equalTo
(
"yyyyMMddHHmmss"
)));
}
@Test
...
...
@@ -165,10 +169,7 @@ public class JacksonAutoConfigurationTests {
"spring.jackson.date-format:org.springframework.boot.autoconfigure.jackson.JacksonAutoConfigurationTests.MyDateFormat"
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
DateTime
dateTime
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
,
DateTimeZone
.
UTC
);
assertEquals
(
"\"1988-06-25T20:30:00.000Z\""
,
mapper
.
writeValueAsString
(
dateTime
));
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
();
assertEquals
(
"\"1988-06-25 20:30:00\""
,
mapper
.
writeValueAsString
(
date
));
assertThat
(
mapper
.
getDateFormat
(),
is
(
instanceOf
(
MyDateFormat
.
class
)));
}
public
static
class
MyDateFormat
extends
SimpleDateFormat
{
...
...
@@ -178,50 +179,24 @@ public class JacksonAutoConfigurationTests {
}
}
/*
* ObjectMapper does not contain method to get the property naming strategy of the
* mapper. See https://github.com/FasterXML/jackson-databind/issues/559 If such a
* method will be provided below tests can be simplified.
*/
@Test
public
void
noCustomPropertyNamingStrategy
()
throws
Exception
{
this
.
context
.
register
(
JacksonAutoConfiguration
.
class
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
assert
Equals
(
"{\"propertyName\":null}"
,
mapper
.
writeValueAsString
(
new
Bar
()));
assert
That
(
mapper
.
getPropertyNamingStrategy
(),
is
(
nullValue
()));
}
@Test
public
void
customPropertyNamingStrategyCamelCaseToLowerCaseWithUnderscores
()
throws
Exception
{
public
void
customPropertyNamingStrategyField
()
throws
Exception
{
this
.
context
.
register
(
JacksonAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.jackson.property-naming-strategy:CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES"
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
assertEquals
(
"{\"property_name\":null}"
,
mapper
.
writeValueAsString
(
new
Bar
()));
}
@Test
public
void
customPropertyNamingStrategyPascalCaseToCamelCase
()
throws
Exception
{
this
.
context
.
register
(
JacksonAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.jackson.property-naming-strategy:PASCAL_CASE_TO_CAMEL_CASE"
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
assertEquals
(
"{\"PropertyName\":null}"
,
mapper
.
writeValueAsString
(
new
Bar
()));
}
@Test
public
void
customPropertyNamingStrategyLowerCase
()
throws
Exception
{
this
.
context
.
register
(
JacksonAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.jackson.property-naming-strategy:LOWER_CASE"
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
assertEquals
(
"{\"propertyname\":null}"
,
mapper
.
writeValueAsString
(
new
Bar
()));
assertThat
(
mapper
.
getPropertyNamingStrategy
(),
is
(
instanceOf
(
LowerCaseWithUnderscoresStrategy
.
class
)));
}
@Test
...
...
@@ -233,7 +208,8 @@ public class JacksonAutoConfigurationTests {
"spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy"
);
this
.
context
.
refresh
();
ObjectMapper
mapper
=
this
.
context
.
getBean
(
ObjectMapper
.
class
);
assertEquals
(
"{\"property_name\":null}"
,
mapper
.
writeValueAsString
(
new
Bar
()));
assertThat
(
mapper
.
getPropertyNamingStrategy
(),
is
(
instanceOf
(
LowerCaseWithUnderscoresStrategy
.
class
)));
}
@Test
...
...
spring-boot-dependencies/pom.xml
View file @
99de71bf
...
...
@@ -77,7 +77,7 @@
<hsqldb.version>
2.3.2
</hsqldb.version>
<httpasyncclient.version>
4.0.2
</httpasyncclient.version>
<httpclient.version>
4.3.6
</httpclient.version>
<jackson.version>
2.
4.5
</jackson.version>
<jackson.version>
2.
5.1
</jackson.version>
<janino.version>
2.6.1
</janino.version>
<javassist.version>
3.18.1-GA
</javassist.version>
<!-- Same as Hibernate -->
<javax-cache.version>
1.0.0
</javax-cache.version>
...
...
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