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
c4592e7d
Commit
c4592e7d
authored
Jan 15, 2020
by
Scott Frederick
Committed by
Stephane Nicoll
Jan 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deprecated Joda-Time support
See gh-19699
parent
8f102aee
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
7 additions
and
164 deletions
+7
-164
build.gradle
spring-boot-project/spring-boot-autoconfigure/build.gradle
+0
-1
JacksonAutoConfiguration.java
.../boot/autoconfigure/jackson/JacksonAutoConfiguration.java
+1
-51
JacksonProperties.java
...amework/boot/autoconfigure/jackson/JacksonProperties.java
+1
-20
WebConversionService.java
...k/boot/autoconfigure/web/format/WebConversionService.java
+1
-20
JacksonAutoConfigurationTests.java
.../autoconfigure/jackson/JacksonAutoConfigurationTests.java
+3
-63
WebConversionServiceTests.java
...t/autoconfigure/web/format/WebConversionServiceTests.java
+1
-9
No files found.
spring-boot-project/spring-boot-autoconfigure/build.gradle
View file @
c4592e7d
...
...
@@ -21,7 +21,6 @@ dependencies {
optional
'com.fasterxml.jackson.core:jackson-databind'
optional
'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor'
optional
'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
optional
'com.fasterxml.jackson.datatype:jackson-datatype-joda'
optional
'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
optional
'com.fasterxml.jackson.module:jackson-module-parameter-names'
optional
'com.google.code.gson:gson'
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java
View file @
c4592e7d
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -34,14 +34,7 @@ import com.fasterxml.jackson.databind.Module;
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.module.paramnames.ParameterNamesModule
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.joda.time.DateTime
;
import
org.joda.time.format.DateTimeFormat
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
...
...
@@ -110,49 +103,6 @@ public class JacksonAutoConfiguration {
}
@Deprecated
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
Jackson2ObjectMapperBuilder
.
class
,
DateTime
.
class
,
DateTimeSerializer
.
class
,
JacksonJodaDateFormat
.
class
})
static
class
JodaDateTimeJacksonConfiguration
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
JodaDateTimeJacksonConfiguration
.
class
);
@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
)
{
module
.
addSerializer
(
DateTime
.
class
,
new
DateTimeSerializer
(
jacksonJodaFormat
,
0
));
}
return
module
;
}
private
JacksonJodaDateFormat
getJacksonJodaDateFormat
(
JacksonProperties
jacksonProperties
)
{
if
(
jacksonProperties
.
getJodaDateTimeFormat
()
!=
null
)
{
return
new
JacksonJodaDateFormat
(
DateTimeFormat
.
forPattern
(
jacksonProperties
.
getJodaDateTimeFormat
()).
withZoneUTC
());
}
if
(
jacksonProperties
.
getDateFormat
()
!=
null
)
{
try
{
return
new
JacksonJodaDateFormat
(
DateTimeFormat
.
forPattern
(
jacksonProperties
.
getDateFormat
()).
withZoneUTC
());
}
catch
(
IllegalArgumentException
ex
)
{
if
(
logger
.
isWarnEnabled
())
{
logger
.
warn
(
"spring.jackson.date-format could not be used to "
+
"configure formatting of Joda's DateTime. You may want "
+
"to configure spring.jackson.joda-date-time-format as well."
);
}
}
}
return
null
;
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
(
ParameterNamesModule
.
class
)
static
class
ParameterNamesModuleConfiguration
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonProperties.java
View file @
c4592e7d
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -31,7 +31,6 @@ 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.
...
...
@@ -50,12 +49,6 @@ public class JacksonProperties {
*/
private
String
dateFormat
;
/**
* Joda date time format string. If not configured, "date-format" is used as a
* fallback if it is configured with a format string.
*/
private
String
jodaDateTimeFormat
;
/**
* One of the constants on Jackson's PropertyNamingStrategy. Can also be a
* fully-qualified class name of a PropertyNamingStrategy subclass.
...
...
@@ -118,18 +111,6 @@ 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
;
}
public
void
setJodaDateTimeFormat
(
String
jodaDataTimeFormat
)
{
this
.
jodaDateTimeFormat
=
jodaDataTimeFormat
;
}
public
String
getPropertyNamingStrategy
()
{
return
this
.
propertyNamingStrategy
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java
View file @
c4592e7d
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -21,11 +21,9 @@ 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
;
import
org.springframework.format.datetime.DateFormatterRegistrar
;
import
org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar
;
import
org.springframework.format.datetime.standard.DateTimeFormatterRegistrar
;
import
org.springframework.format.number.NumberFormatAnnotationFormatterFactory
;
import
org.springframework.format.number.money.CurrencyUnitFormatter
;
...
...
@@ -51,10 +49,6 @@ 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
;
...
...
@@ -83,9 +77,6 @@ public class WebConversionService extends DefaultFormattingConversionService {
addFormatterForFieldAnnotation
(
new
Jsr354NumberFormatAnnotationFormatterFactory
());
}
registerJsr310
();
if
(
JODA_TIME_PRESENT
)
{
registerJodaTime
();
}
registerJavaDate
();
}
...
...
@@ -98,16 +89,6 @@ 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
());
}
jodaTime
.
registerFormatters
(
this
);
}
private
void
registerJavaDate
()
{
DateFormatterRegistrar
dateFormatterRegistrar
=
new
DateFormatterRegistrar
();
if
(
this
.
dateFormat
!=
null
)
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java
View file @
c4592e7d
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -29,7 +29,6 @@ import com.fasterxml.jackson.annotation.JsonCreator.Mode;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.ObjectCodec
;
import
com.fasterxml.jackson.databind.AnnotationIntrospector
;
import
com.fasterxml.jackson.databind.DeserializationConfig
;
...
...
@@ -43,11 +42,7 @@ 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
com.fasterxml.jackson.datatype.joda.cfg.FormatConfig
;
import
com.fasterxml.jackson.module.paramnames.ParameterNamesModule
;
import
org.joda.time.DateTime
;
import
org.joda.time.DateTimeZone
;
import
org.joda.time.LocalDateTime
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
...
@@ -80,15 +75,6 @@ class JacksonAutoConfigurationTests {
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
JacksonAutoConfiguration
.
class
));
@Test
@Deprecated
void
registersJodaModuleAutomatically
()
{
this
.
contextRunner
.
run
((
context
)
->
{
ObjectMapper
objectMapper
=
context
.
getBean
(
ObjectMapper
.
class
);
assertThat
(
objectMapper
.
canSerialize
(
LocalDateTime
.
class
)).
isTrue
();
});
}
@Test
void
doubleModuleRegistration
()
{
this
.
contextRunner
.
withUserConfiguration
(
DoubleModulesConfig
.
class
)
...
...
@@ -117,19 +103,6 @@ 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
)
->
{
ObjectMapper
mapper
=
context
.
getBean
(
ObjectMapper
.
class
);
DateTime
dateTime
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
,
DateTimeZone
.
UTC
);
assertThat
(
mapper
.
writeValueAsString
(
dateTime
)).
isEqualTo
(
"\"1988-06-25 20:30:00\""
);
Date
date
=
dateTime
.
toDate
();
assertThat
(
mapper
.
writeValueAsString
(
date
)).
isEqualTo
(
"\"19880625203000\""
);
});
}
@Test
void
customDateFormatClass
()
{
this
.
contextRunner
.
withPropertyValues
(
...
...
@@ -294,8 +267,7 @@ class JacksonAutoConfigurationTests {
void
moduleBeansAndWellKnownModulesAreRegisteredWithTheObjectMapperBuilder
()
{
this
.
contextRunner
.
withUserConfiguration
(
ModuleConfig
.
class
).
run
((
context
)
->
{
ObjectMapper
objectMapper
=
context
.
getBean
(
Jackson2ObjectMapperBuilder
.
class
).
build
();
assertThat
(
context
.
getBean
(
CustomModule
.
class
).
getOwners
()).
contains
((
ObjectCodec
)
objectMapper
);
assertThat
(
objectMapper
.
canSerialize
(
LocalDateTime
.
class
)).
isTrue
();
assertThat
(
context
.
getBean
(
CustomModule
.
class
).
getOwners
()).
contains
(
objectMapper
);
assertThat
(
objectMapper
.
canSerialize
(
Baz
.
class
)).
isTrue
();
});
}
...
...
@@ -319,17 +291,7 @@ class JacksonAutoConfigurationTests {
}
@Test
void
customTimeZoneFormattingADateTime
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.jackson.time-zone:America/Los_Angeles"
,
"spring.jackson.date-format:zzzz"
,
"spring.jackson.locale:en"
).
run
((
context
)
->
{
ObjectMapper
objectMapper
=
context
.
getBean
(
Jackson2ObjectMapperBuilder
.
class
).
build
();
DateTime
dateTime
=
new
DateTime
(
1436966242231L
,
DateTimeZone
.
UTC
);
assertThat
(
objectMapper
.
writeValueAsString
(
dateTime
)).
isEqualTo
(
"\"Pacific Daylight Time\""
);
});
}
@Test
void
customTimeZoneFormattingADate
()
throws
JsonProcessingException
{
void
customTimeZoneFormattingADate
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.jackson.time-zone:GMT+10"
,
"spring.jackson.date-format:z"
)
.
run
((
context
)
->
{
ObjectMapper
objectMapper
=
context
.
getBean
(
Jackson2ObjectMapperBuilder
.
class
).
build
();
...
...
@@ -338,17 +300,6 @@ 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
)
->
{
ObjectMapper
objectMapper
=
context
.
getBean
(
ObjectMapper
.
class
);
DateTime
jodaTime
=
new
DateTime
(
1478424650000L
,
DateTimeZone
.
forID
(
"Europe/Rome"
));
assertThat
(
objectMapper
.
writeValueAsString
(
jodaTime
)).
startsWith
(
"\"Mitteleuropäische "
);
});
}
@Test
void
additionalJacksonBuilderCustomization
()
{
this
.
contextRunner
.
withUserConfiguration
(
ObjectMapperBuilderCustomConfig
.
class
).
run
((
context
)
->
{
...
...
@@ -368,17 +319,6 @@ class JacksonAutoConfigurationTests {
JacksonAutoConfiguration
.
class
);
}
@Test
void
writeDatesAsTimestampsDefault
()
{
this
.
contextRunner
.
run
((
context
)
->
{
ObjectMapper
mapper
=
context
.
getBean
(
ObjectMapper
.
class
);
DateTime
dateTime
=
new
DateTime
(
1988
,
6
,
25
,
20
,
30
,
DateTimeZone
.
UTC
);
String
expected
=
FormatConfig
.
DEFAULT_DATETIME_PRINTER
.
rawFormatter
().
withZone
(
DateTimeZone
.
UTC
)
.
print
(
dateTime
);
assertThat
(
mapper
.
writeValueAsString
(
dateTime
)).
isEqualTo
(
"\""
+
expected
+
"\""
);
});
}
@Test
void
writeDurationAsTimestampsDefault
()
{
this
.
contextRunner
.
run
((
context
)
->
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java
View file @
c4592e7d
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -20,8 +20,6 @@ import java.time.ZoneId;
import
java.time.ZonedDateTime
;
import
java.util.Date
;
import
org.joda.time.DateTime
;
import
org.joda.time.LocalDate
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -39,12 +37,6 @@ class WebConversionServiceTests {
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
));
...
...
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