Remove Joda-Time support
Closes gh-27426
This commit is contained in:
@@ -84,8 +84,6 @@ import org.springframework.util.xml.StaxUtils;
|
||||
* support for other Java 8 types like {@link java.util.Optional}</li>
|
||||
* <li><a href="https://github.com/FasterXML/jackson-datatype-jsr310">jackson-datatype-jsr310</a>:
|
||||
* support for Java 8 Date & Time API types</li>
|
||||
* <li><a href="https://github.com/FasterXML/jackson-datatype-joda">jackson-datatype-joda</a>:
|
||||
* support for Joda-Time types</li>
|
||||
* <li><a href="https://github.com/FasterXML/jackson-module-kotlin">jackson-module-kotlin</a>:
|
||||
* support for Kotlin classes and data classes</li>
|
||||
* </ul>
|
||||
@@ -836,19 +834,6 @@ public class Jackson2ObjectMapperBuilder {
|
||||
// jackson-datatype-jsr310 not available
|
||||
}
|
||||
|
||||
// Joda-Time 2.x present?
|
||||
if (ClassUtils.isPresent("org.joda.time.YearMonth", this.moduleClassLoader)) {
|
||||
try {
|
||||
Class<? extends Module> jodaModuleClass = (Class<? extends Module>)
|
||||
ClassUtils.forName("com.fasterxml.jackson.datatype.joda.JodaModule", this.moduleClassLoader);
|
||||
Module jodaModule = BeanUtils.instantiateClass(jodaModuleClass);
|
||||
modulesToRegister.set(jodaModule.getTypeId(), jodaModule);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// jackson-datatype-joda not available
|
||||
}
|
||||
}
|
||||
|
||||
// Kotlin present?
|
||||
if (KotlinDetector.isKotlinPresent()) {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -120,8 +120,6 @@ import org.springframework.lang.Nullable;
|
||||
* support for other Java 8 types like {@link java.util.Optional}</li>
|
||||
* <li><a href="https://github.com/FasterXML/jackson-datatype-jsr310">jackson-datatype-jsr310</a>:
|
||||
* support for Java 8 Date & Time API types</li>
|
||||
* <li><a href="https://github.com/FasterXML/jackson-datatype-joda">jackson-datatype-joda</a>:
|
||||
* support for Joda-Time types</li>
|
||||
* <li><a href="https://github.com/FasterXML/jackson-module-kotlin">jackson-module-kotlin</a>:
|
||||
* support for Kotlin classes and data classes</li>
|
||||
* </ul>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -79,8 +79,6 @@ import com.fasterxml.jackson.dataformat.xml.XmlFactory;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import kotlin.ranges.IntRange;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
@@ -263,10 +261,6 @@ class Jackson2ObjectMapperBuilderTests {
|
||||
void wellKnownModules() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||
|
||||
Long timestamp = 1322903730000L;
|
||||
DateTime dateTime = new DateTime(timestamp, DateTimeZone.UTC);
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo(timestamp.toString());
|
||||
|
||||
Path file = Paths.get("foo");
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(file), "UTF-8").endsWith("foo\"")).isTrue();
|
||||
|
||||
@@ -278,41 +272,6 @@ class Jackson2ObjectMapperBuilderTests {
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(range), "UTF-8")).isEqualTo("{\"start\":1,\"end\":3}");
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
void customizeWellKnownModulesWithModule()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(new CustomIntegerModule())
|
||||
.build();
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo("1322903730000");
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(4), "UTF-8")).contains("customid");
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
void customizeWellKnownModulesWithModuleClass()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.modulesToInstall(CustomIntegerModule.class)
|
||||
.build();
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo("1322903730000");
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(4), "UTF-8")).contains("customid");
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
void customizeWellKnownModulesWithSerializer()
|
||||
throws JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.serializerByType(Integer.class, new CustomIntegerSerializer()).build();
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo("1322903730000");
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(4), "UTF-8")).contains("customid");
|
||||
}
|
||||
|
||||
@Test // gh-22576
|
||||
void overrideWellKnownModuleWithModule() throws IOException {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.http.converter.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -58,8 +57,6 @@ import com.fasterxml.jackson.databind.ser.std.NumberSerializer;
|
||||
import com.fasterxml.jackson.databind.type.SimpleType;
|
||||
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
@@ -202,41 +199,6 @@ public class Jackson2ObjectMapperFactoryBeanTests {
|
||||
assertThat(serializers.findSerializer(null, SimpleType.construct(Integer.class), null)).isSameAs(serializer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultModules() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
this.factory.afterPropertiesSet();
|
||||
ObjectMapper objectMapper = this.factory.getObject();
|
||||
|
||||
Long timestamp = 1322903730000L;
|
||||
DateTime dateTime = new DateTime(timestamp, DateTimeZone.UTC);
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo(timestamp.toString());
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
public void customizeDefaultModulesWithModuleClass() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
this.factory.setModulesToInstall(CustomIntegerModule.class);
|
||||
this.factory.afterPropertiesSet();
|
||||
ObjectMapper objectMapper = this.factory.getObject();
|
||||
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo("1322903730000");
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(4), "UTF-8")).contains("customid");
|
||||
}
|
||||
|
||||
@Test // SPR-12634
|
||||
public void customizeDefaultModulesWithSerializer() throws JsonProcessingException, UnsupportedEncodingException {
|
||||
Map<Class<?>, JsonSerializer<?>> serializers = new HashMap<>();
|
||||
serializers.put(Integer.class, new CustomIntegerSerializer());
|
||||
|
||||
this.factory.setSerializersByType(serializers);
|
||||
this.factory.afterPropertiesSet();
|
||||
ObjectMapper objectMapper = this.factory.getObject();
|
||||
|
||||
DateTime dateTime = new DateTime(1322903730000L, DateTimeZone.UTC);
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8")).isEqualTo("1322903730000");
|
||||
assertThat(new String(objectMapper.writeValueAsBytes(4), "UTF-8")).contains("customid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleSetup() {
|
||||
this.factory.afterPropertiesSet();
|
||||
|
||||
Reference in New Issue
Block a user