parent
8f102aee68
commit
c4592e7df8
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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 {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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) -> {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue