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
3e6c15c4
Commit
3e6c15c4
authored
Jul 09, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deprecate auto-configuration for Joda-Time
Closes gh-17419
parent
9f253603
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
17 deletions
+49
-17
JacksonAutoConfiguration.java
.../boot/autoconfigure/jackson/JacksonAutoConfiguration.java
+3
-0
JacksonProperties.java
...amework/boot/autoconfigure/jackson/JacksonProperties.java
+5
-0
WebConversionService.java
...k/boot/autoconfigure/web/format/WebConversionService.java
+7
-0
GsonAutoConfigurationTests.java
...k/boot/autoconfigure/gson/GsonAutoConfigurationTests.java
+4
-4
JacksonAutoConfigurationTests.java
.../autoconfigure/jackson/JacksonAutoConfigurationTests.java
+3
-0
WebConversionServiceTests.java
...t/autoconfigure/web/format/WebConversionServiceTests.java
+19
-7
WebFluxAutoConfigurationTests.java
...configure/web/reactive/WebFluxAutoConfigurationTests.java
+4
-3
WebMvcAutoConfigurationTests.java
...toconfigure/web/servlet/WebMvcAutoConfigurationTests.java
+4
-3
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java
View file @
3e6c15c4
...
...
@@ -108,6 +108,7 @@ public class JacksonAutoConfiguration {
}
@Deprecated
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
Jackson2ObjectMapperBuilder
.
class
,
DateTime
.
class
,
DateTimeSerializer
.
class
,
JacksonJodaDateFormat
.
class
})
...
...
@@ -117,6 +118,8 @@ public class JacksonAutoConfiguration {
@Bean
SimpleModule
jodaDateTimeSerializationModule
(
JacksonProperties
jacksonProperties
)
{
logger
.
warn
(
"Auto-configuration of Jackson's Joda-Time integration is deprecated in favor of using "
+
"java.time (JSR-310)."
);
SimpleModule
module
=
new
SimpleModule
();
JacksonJodaDateFormat
jacksonJodaFormat
=
getJacksonJodaDateFormat
(
jacksonProperties
);
if
(
jacksonJodaFormat
!=
null
)
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonProperties.java
View file @
3e6c15c4
...
...
@@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.MapperFeature;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.DeprecatedConfigurationProperty
;
/**
* Configuration properties to configure Jackson.
...
...
@@ -117,6 +118,10 @@ public class JacksonProperties {
this
.
dateFormat
=
dateFormat
;
}
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"dateFormat"
,
reason
=
"Auto-configuration for Jackson's Joda-Time integration is "
+
"deprecated in favor of its Java 8 Time integration"
)
public
String
getJodaDateTimeFormat
()
{
return
this
.
jodaDateTimeFormat
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java
View file @
3e6c15c4
...
...
@@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.web.format;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.ResolverStyle
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.joda.time.format.DateTimeFormatterBuilder
;
import
org.springframework.format.datetime.DateFormatter
;
...
...
@@ -49,9 +51,12 @@ public class WebConversionService extends DefaultFormattingConversionService {
private
static
final
boolean
JSR_354_PRESENT
=
ClassUtils
.
isPresent
(
"javax.money.MonetaryAmount"
,
WebConversionService
.
class
.
getClassLoader
());
@Deprecated
private
static
final
boolean
JODA_TIME_PRESENT
=
ClassUtils
.
isPresent
(
"org.joda.time.LocalDate"
,
WebConversionService
.
class
.
getClassLoader
());
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WebConversionService
.
class
);
private
final
String
dateFormat
;
/**
...
...
@@ -93,7 +98,9 @@ public class WebConversionService extends DefaultFormattingConversionService {
dateTime
.
registerFormatters
(
this
);
}
@Deprecated
private
void
registerJodaTime
()
{
logger
.
warn
(
"Auto-configuration of Joda-Time formatters is deprecated in favor of using java.time (JSR-310)."
);
JodaTimeFormatterRegistrar
jodaTime
=
new
JodaTimeFormatterRegistrar
();
if
(
this
.
dateFormat
!=
null
)
{
jodaTime
.
setDateFormatter
(
new
DateTimeFormatterBuilder
().
appendPattern
(
this
.
dateFormat
).
toFormatter
());
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java
View file @
3e6c15c4
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
gson
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
...
...
@@ -26,7 +28,6 @@ import com.google.gson.FieldNamingPolicy;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.LongSerializationPolicy
;
import
org.joda.time.DateTime
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
...
@@ -198,9 +199,8 @@ class GsonAutoConfigurationTests {
void
customDateFormat
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.gson.date-format:H"
).
run
((
context
)
->
{
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
DateTime
dateTime
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
);
Date
date
=
dateTime
.
toDate
();
assertThat
(
gson
.
toJson
(
date
)).
isEqualTo
(
"\"20\""
);
ZonedDateTime
dateTime
=
ZonedDateTime
.
of
(
1988
,
6
,
25
,
20
,
30
,
0
,
0
,
ZoneId
.
systemDefault
());
assertThat
(
gson
.
toJson
(
Date
.
from
(
dateTime
.
toInstant
()))).
isEqualTo
(
"\"20\""
);
});
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java
View file @
3e6c15c4
...
...
@@ -80,6 +80,7 @@ class JacksonAutoConfigurationTests {
.
withConfiguration
(
AutoConfigurations
.
of
(
JacksonAutoConfiguration
.
class
));
@Test
@Deprecated
void
registersJodaModuleAutomatically
()
{
this
.
contextRunner
.
run
((
context
)
->
{
ObjectMapper
objectMapper
=
context
.
getBean
(
ObjectMapper
.
class
);
...
...
@@ -116,6 +117,7 @@ class JacksonAutoConfigurationTests {
}
@Test
@Deprecated
void
customJodaDateTimeFormat
()
throws
Exception
{
this
.
contextRunner
.
withPropertyValues
(
"spring.jackson.date-format:yyyyMMddHHmmss"
,
"spring.jackson.joda-date-time-format:yyyy-MM-dd HH:mm:ss"
).
run
((
context
)
->
{
...
...
@@ -336,6 +338,7 @@ class JacksonAutoConfigurationTests {
}
@Test
@Deprecated
void
customLocaleWithJodaTime
()
throws
JsonProcessingException
{
this
.
contextRunner
.
withPropertyValues
(
"spring.jackson.locale:de_DE"
,
"spring.jackson.date-format:zzzz"
,
"spring.jackson.serialization.write-dates-with-zone-id:true"
).
run
((
context
)
->
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java
View file @
3e6c15c4
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
format
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.util.Date
;
import
org.joda.time.DateTime
;
...
...
@@ -33,14 +35,24 @@ import static org.assertj.core.api.Assertions.assertThat;
class
WebConversionServiceTests
{
@Test
void
customDateFormat
()
{
void
customDateFormatWithJavaUtilDate
()
{
customDateFormat
(
Date
.
from
(
ZonedDateTime
.
of
(
2018
,
1
,
1
,
20
,
30
,
0
,
0
,
ZoneId
.
systemDefault
()).
toInstant
()));
}
@Test
@Deprecated
void
customDateFormatWithJodaTime
()
{
customDateFormat
(
LocalDate
.
fromDateFields
(
new
DateTime
(
2018
,
1
,
1
,
20
,
30
).
toDate
()));
}
@Test
void
customDateFormatWithJavaTime
()
{
customDateFormat
(
java
.
time
.
LocalDate
.
of
(
2018
,
1
,
1
));
}
private
void
customDateFormat
(
Object
input
)
{
WebConversionService
conversionService
=
new
WebConversionService
(
"dd*MM*yyyy"
);
Date
date
=
new
DateTime
(
2018
,
1
,
1
,
20
,
30
).
toDate
();
assertThat
(
conversionService
.
convert
(
date
,
String
.
class
)).
isEqualTo
(
"01*01*2018"
);
LocalDate
jodaDate
=
LocalDate
.
fromDateFields
(
date
);
assertThat
(
conversionService
.
convert
(
jodaDate
,
String
.
class
)).
isEqualTo
(
"01*01*2018"
);
java
.
time
.
LocalDate
localDate
=
java
.
time
.
LocalDate
.
of
(
2018
,
1
,
1
);
assertThat
(
conversionService
.
convert
(
localDate
,
String
.
class
)).
isEqualTo
(
"01*01*2018"
);
assertThat
(
conversionService
.
convert
(
input
,
String
.
class
)).
isEqualTo
(
"01*01*2018"
);
}
@Test
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java
View file @
3e6c15c4
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
reactive
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -26,7 +28,6 @@ import java.util.concurrent.TimeUnit;
import
javax.validation.ValidatorFactory
;
import
org.assertj.core.api.Assertions
;
import
org.joda.time.DateTime
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
...
@@ -187,7 +188,7 @@ class WebFluxAutoConfigurationTests {
void
noDateFormat
()
{
this
.
contextRunner
.
run
((
context
)
->
{
FormattingConversionService
conversionService
=
context
.
getBean
(
FormattingConversionService
.
class
);
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
(
);
Date
date
=
Date
.
from
(
ZonedDateTime
.
of
(
1988
,
6
,
25
,
20
,
30
,
0
,
0
,
ZoneId
.
systemDefault
()).
toInstant
()
);
// formatting conversion service should use simple toString()
assertThat
(
conversionService
.
convert
(
date
,
String
.
class
)).
isEqualTo
(
date
.
toString
());
});
...
...
@@ -197,7 +198,7 @@ class WebFluxAutoConfigurationTests {
void
overrideDateFormat
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.webflux.date-format:dd*MM*yyyy"
).
run
((
context
)
->
{
FormattingConversionService
conversionService
=
context
.
getBean
(
FormattingConversionService
.
class
);
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
(
);
Date
date
=
Date
.
from
(
ZonedDateTime
.
of
(
1988
,
6
,
25
,
20
,
30
,
0
,
0
,
ZoneId
.
systemDefault
()).
toInstant
()
);
assertThat
(
conversionService
.
convert
(
date
,
String
.
class
)).
isEqualTo
(
"25*06*1988"
);
});
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java
View file @
3e6c15c4
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
.
servlet
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
...
...
@@ -30,7 +32,6 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.ValidatorFactory
;
import
org.joda.time.DateTime
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
...
@@ -321,7 +322,7 @@ class WebMvcAutoConfigurationTests {
void
noDateFormat
()
{
this
.
contextRunner
.
run
((
context
)
->
{
FormattingConversionService
conversionService
=
context
.
getBean
(
FormattingConversionService
.
class
);
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
(
);
Date
date
=
Date
.
from
(
ZonedDateTime
.
of
(
1988
,
6
,
25
,
20
,
30
,
0
,
0
,
ZoneId
.
systemDefault
()).
toInstant
()
);
// formatting conversion service should use simple toString()
assertThat
(
conversionService
.
convert
(
date
,
String
.
class
)).
isEqualTo
(
date
.
toString
());
});
...
...
@@ -331,7 +332,7 @@ class WebMvcAutoConfigurationTests {
void
overrideDateFormat
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.mvc.date-format:dd*MM*yyyy"
).
run
((
context
)
->
{
FormattingConversionService
conversionService
=
context
.
getBean
(
FormattingConversionService
.
class
);
Date
date
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
).
toDate
(
);
Date
date
=
Date
.
from
(
ZonedDateTime
.
of
(
1988
,
6
,
25
,
20
,
30
,
0
,
0
,
ZoneId
.
systemDefault
()).
toInstant
()
);
assertThat
(
conversionService
.
convert
(
date
,
String
.
class
)).
isEqualTo
(
"25*06*1988"
);
});
}
...
...
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