Skip to content

Commit c4592e7

Browse files
scottfredericksnicoll
authored andcommitted
Remove deprecated Joda-Time support
See gh-19699
1 parent 8f102ae commit c4592e7

File tree

6 files changed

+7
-164
lines changed

6 files changed

+7
-164
lines changed

spring-boot-project/spring-boot-autoconfigure/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ dependencies {
2121
optional 'com.fasterxml.jackson.core:jackson-databind'
2222
optional 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor'
2323
optional 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
24-
optional 'com.fasterxml.jackson.datatype:jackson-datatype-joda'
2524
optional 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
2625
optional 'com.fasterxml.jackson.module:jackson-module-parameter-names'
2726
optional 'com.google.code.gson:gson'

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,14 +34,7 @@
3434
import com.fasterxml.jackson.databind.ObjectMapper;
3535
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
3636
import com.fasterxml.jackson.databind.SerializationFeature;
37-
import com.fasterxml.jackson.databind.module.SimpleModule;
38-
import com.fasterxml.jackson.datatype.joda.cfg.JacksonJodaDateFormat;
39-
import com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer;
4037
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
41-
import org.apache.commons.logging.Log;
42-
import org.apache.commons.logging.LogFactory;
43-
import org.joda.time.DateTime;
44-
import org.joda.time.format.DateTimeFormat;
4538

4639
import org.springframework.beans.BeanUtils;
4740
import org.springframework.beans.factory.BeanFactoryUtils;
@@ -110,49 +103,6 @@ ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
110103

111104
}
112105

113-
@Deprecated
114-
@Configuration(proxyBeanMethods = false)
115-
@ConditionalOnClass({ Jackson2ObjectMapperBuilder.class, DateTime.class, DateTimeSerializer.class,
116-
JacksonJodaDateFormat.class })
117-
static class JodaDateTimeJacksonConfiguration {
118-
119-
private static final Log logger = LogFactory.getLog(JodaDateTimeJacksonConfiguration.class);
120-
121-
@Bean
122-
SimpleModule jodaDateTimeSerializationModule(JacksonProperties jacksonProperties) {
123-
logger.warn("Auto-configuration of Jackson's Joda-Time integration is deprecated in favor of using "
124-
+ "java.time (JSR-310).");
125-
SimpleModule module = new SimpleModule();
126-
JacksonJodaDateFormat jacksonJodaFormat = getJacksonJodaDateFormat(jacksonProperties);
127-
if (jacksonJodaFormat != null) {
128-
module.addSerializer(DateTime.class, new DateTimeSerializer(jacksonJodaFormat, 0));
129-
}
130-
return module;
131-
}
132-
133-
private JacksonJodaDateFormat getJacksonJodaDateFormat(JacksonProperties jacksonProperties) {
134-
if (jacksonProperties.getJodaDateTimeFormat() != null) {
135-
return new JacksonJodaDateFormat(
136-
DateTimeFormat.forPattern(jacksonProperties.getJodaDateTimeFormat()).withZoneUTC());
137-
}
138-
if (jacksonProperties.getDateFormat() != null) {
139-
try {
140-
return new JacksonJodaDateFormat(
141-
DateTimeFormat.forPattern(jacksonProperties.getDateFormat()).withZoneUTC());
142-
}
143-
catch (IllegalArgumentException ex) {
144-
if (logger.isWarnEnabled()) {
145-
logger.warn("spring.jackson.date-format could not be used to "
146-
+ "configure formatting of Joda's DateTime. You may want "
147-
+ "to configure spring.jackson.joda-date-time-format as well.");
148-
}
149-
}
150-
}
151-
return null;
152-
}
153-
154-
}
155-
156106
@Configuration(proxyBeanMethods = false)
157107
@ConditionalOnClass(ParameterNamesModule.class)
158108
static class ParameterNamesModuleConfiguration {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonProperties.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
3131
import com.fasterxml.jackson.databind.SerializationFeature;
3232

3333
import org.springframework.boot.context.properties.ConfigurationProperties;
34-
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
3534

3635
/**
3736
* Configuration properties to configure Jackson.
@@ -50,12 +49,6 @@ public class JacksonProperties {
5049
*/
5150
private String dateFormat;
5251

53-
/**
54-
* Joda date time format string. If not configured, "date-format" is used as a
55-
* fallback if it is configured with a format string.
56-
*/
57-
private String jodaDateTimeFormat;
58-
5952
/**
6053
* One of the constants on Jackson's PropertyNamingStrategy. Can also be a
6154
* fully-qualified class name of a PropertyNamingStrategy subclass.
@@ -118,18 +111,6 @@ public void setDateFormat(String dateFormat) {
118111
this.dateFormat = dateFormat;
119112
}
120113

121-
@Deprecated
122-
@DeprecatedConfigurationProperty(replacement = "dateFormat",
123-
reason = "Auto-configuration for Jackson's Joda-Time integration is "
124-
+ "deprecated in favor of its Java 8 Time integration")
125-
public String getJodaDateTimeFormat() {
126-
return this.jodaDateTimeFormat;
127-
}
128-
129-
public void setJodaDateTimeFormat(String jodaDataTimeFormat) {
130-
this.jodaDateTimeFormat = jodaDataTimeFormat;
131-
}
132-
133114
public String getPropertyNamingStrategy() {
134115
return this.propertyNamingStrategy;
135116
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/WebConversionService.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,11 +21,9 @@
2121

2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24-
import org.joda.time.format.DateTimeFormatterBuilder;
2524

2625
import org.springframework.format.datetime.DateFormatter;
2726
import org.springframework.format.datetime.DateFormatterRegistrar;
28-
import org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar;
2927
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
3028
import org.springframework.format.number.NumberFormatAnnotationFormatterFactory;
3129
import org.springframework.format.number.money.CurrencyUnitFormatter;
@@ -51,10 +49,6 @@ public class WebConversionService extends DefaultFormattingConversionService {
5149
private static final boolean JSR_354_PRESENT = ClassUtils.isPresent("javax.money.MonetaryAmount",
5250
WebConversionService.class.getClassLoader());
5351

54-
@Deprecated
55-
private static final boolean JODA_TIME_PRESENT = ClassUtils.isPresent("org.joda.time.LocalDate",
56-
WebConversionService.class.getClassLoader());
57-
5852
private static final Log logger = LogFactory.getLog(WebConversionService.class);
5953

6054
private final String dateFormat;
@@ -83,9 +77,6 @@ private void addFormatters() {
8377
addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory());
8478
}
8579
registerJsr310();
86-
if (JODA_TIME_PRESENT) {
87-
registerJodaTime();
88-
}
8980
registerJavaDate();
9081
}
9182

@@ -98,16 +89,6 @@ private void registerJsr310() {
9889
dateTime.registerFormatters(this);
9990
}
10091

101-
@Deprecated
102-
private void registerJodaTime() {
103-
logger.warn("Auto-configuration of Joda-Time formatters is deprecated in favor of using java.time (JSR-310).");
104-
JodaTimeFormatterRegistrar jodaTime = new JodaTimeFormatterRegistrar();
105-
if (this.dateFormat != null) {
106-
jodaTime.setDateFormatter(new DateTimeFormatterBuilder().appendPattern(this.dateFormat).toFormatter());
107-
}
108-
jodaTime.registerFormatters(this);
109-
}
110-
11192
private void registerJavaDate() {
11293
DateFormatterRegistrar dateFormatterRegistrar = new DateFormatterRegistrar();
11394
if (this.dateFormat != null) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@
2929
import com.fasterxml.jackson.annotation.JsonInclude;
3030
import com.fasterxml.jackson.core.JsonGenerator;
3131
import com.fasterxml.jackson.core.JsonParser;
32-
import com.fasterxml.jackson.core.JsonProcessingException;
3332
import com.fasterxml.jackson.core.ObjectCodec;
3433
import com.fasterxml.jackson.databind.AnnotationIntrospector;
3534
import com.fasterxml.jackson.databind.DeserializationConfig;
@@ -43,11 +42,7 @@
4342
import com.fasterxml.jackson.databind.SerializerProvider;
4443
import com.fasterxml.jackson.databind.module.SimpleModule;
4544
import com.fasterxml.jackson.databind.util.StdDateFormat;
46-
import com.fasterxml.jackson.datatype.joda.cfg.FormatConfig;
4745
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
48-
import org.joda.time.DateTime;
49-
import org.joda.time.DateTimeZone;
50-
import org.joda.time.LocalDateTime;
5146
import org.junit.jupiter.api.Test;
5247

5348
import org.springframework.boot.autoconfigure.AutoConfigurations;
@@ -80,15 +75,6 @@ class JacksonAutoConfigurationTests {
8075
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
8176
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class));
8277

83-
@Test
84-
@Deprecated
85-
void registersJodaModuleAutomatically() {
86-
this.contextRunner.run((context) -> {
87-
ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
88-
assertThat(objectMapper.canSerialize(LocalDateTime.class)).isTrue();
89-
});
90-
}
91-
9278
@Test
9379
void doubleModuleRegistration() {
9480
this.contextRunner.withUserConfiguration(DoubleModulesConfig.class)
@@ -117,19 +103,6 @@ void customDateFormat() {
117103
});
118104
}
119105

120-
@Test
121-
@Deprecated
122-
void customJodaDateTimeFormat() throws Exception {
123-
this.contextRunner.withPropertyValues("spring.jackson.date-format:yyyyMMddHHmmss",
124-
"spring.jackson.joda-date-time-format:yyyy-MM-dd HH:mm:ss").run((context) -> {
125-
ObjectMapper mapper = context.getBean(ObjectMapper.class);
126-
DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC);
127-
assertThat(mapper.writeValueAsString(dateTime)).isEqualTo("\"1988-06-25 20:30:00\"");
128-
Date date = dateTime.toDate();
129-
assertThat(mapper.writeValueAsString(date)).isEqualTo("\"19880625203000\"");
130-
});
131-
}
132-
133106
@Test
134107
void customDateFormatClass() {
135108
this.contextRunner.withPropertyValues(
@@ -294,8 +267,7 @@ void defaultObjectMapperBuilder() {
294267
void moduleBeansAndWellKnownModulesAreRegisteredWithTheObjectMapperBuilder() {
295268
this.contextRunner.withUserConfiguration(ModuleConfig.class).run((context) -> {
296269
ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class).build();
297-
assertThat(context.getBean(CustomModule.class).getOwners()).contains((ObjectCodec) objectMapper);
298-
assertThat(objectMapper.canSerialize(LocalDateTime.class)).isTrue();
270+
assertThat(context.getBean(CustomModule.class).getOwners()).contains(objectMapper);
299271
assertThat(objectMapper.canSerialize(Baz.class)).isTrue();
300272
});
301273
}
@@ -319,17 +291,7 @@ void customSerializationInclusion() {
319291
}
320292

321293
@Test
322-
void customTimeZoneFormattingADateTime() {
323-
this.contextRunner.withPropertyValues("spring.jackson.time-zone:America/Los_Angeles",
324-
"spring.jackson.date-format:zzzz", "spring.jackson.locale:en").run((context) -> {
325-
ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class).build();
326-
DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC);
327-
assertThat(objectMapper.writeValueAsString(dateTime)).isEqualTo("\"Pacific Daylight Time\"");
328-
});
329-
}
330-
331-
@Test
332-
void customTimeZoneFormattingADate() throws JsonProcessingException {
294+
void customTimeZoneFormattingADate() {
333295
this.contextRunner.withPropertyValues("spring.jackson.time-zone:GMT+10", "spring.jackson.date-format:z")
334296
.run((context) -> {
335297
ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class).build();
@@ -338,17 +300,6 @@ void customTimeZoneFormattingADate() throws JsonProcessingException {
338300
});
339301
}
340302

341-
@Test
342-
@Deprecated
343-
void customLocaleWithJodaTime() throws JsonProcessingException {
344-
this.contextRunner.withPropertyValues("spring.jackson.locale:de_DE", "spring.jackson.date-format:zzzz",
345-
"spring.jackson.serialization.write-dates-with-zone-id:true").run((context) -> {
346-
ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
347-
DateTime jodaTime = new DateTime(1478424650000L, DateTimeZone.forID("Europe/Rome"));
348-
assertThat(objectMapper.writeValueAsString(jodaTime)).startsWith("\"Mitteleuropäische ");
349-
});
350-
}
351-
352303
@Test
353304
void additionalJacksonBuilderCustomization() {
354305
this.contextRunner.withUserConfiguration(ObjectMapperBuilderCustomConfig.class).run((context) -> {
@@ -368,17 +319,6 @@ void customParameterNamesModuleCanBeConfigured() {
368319
JacksonAutoConfiguration.class);
369320
}
370321

371-
@Test
372-
void writeDatesAsTimestampsDefault() {
373-
this.contextRunner.run((context) -> {
374-
ObjectMapper mapper = context.getBean(ObjectMapper.class);
375-
DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC);
376-
String expected = FormatConfig.DEFAULT_DATETIME_PRINTER.rawFormatter().withZone(DateTimeZone.UTC)
377-
.print(dateTime);
378-
assertThat(mapper.writeValueAsString(dateTime)).isEqualTo("\"" + expected + "\"");
379-
});
380-
}
381-
382322
@Test
383323
void writeDurationAsTimestampsDefault() {
384324
this.contextRunner.run((context) -> {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
2020
import java.time.ZonedDateTime;
2121
import java.util.Date;
2222

23-
import org.joda.time.DateTime;
24-
import org.joda.time.LocalDate;
2523
import org.junit.jupiter.api.Test;
2624

2725
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,12 +37,6 @@ void customDateFormatWithJavaUtilDate() {
3937
customDateFormat(Date.from(ZonedDateTime.of(2018, 1, 1, 20, 30, 0, 0, ZoneId.systemDefault()).toInstant()));
4038
}
4139

42-
@Test
43-
@Deprecated
44-
void customDateFormatWithJodaTime() {
45-
customDateFormat(LocalDate.fromDateFields(new DateTime(2018, 1, 1, 20, 30).toDate()));
46-
}
47-
4840
@Test
4941
void customDateFormatWithJavaTime() {
5042
customDateFormat(java.time.LocalDate.of(2018, 1, 1));

0 commit comments

Comments
 (0)