Merge branch '6.0.x'

This commit is contained in:
Juergen Hoeller
2023-06-26 12:35:56 +02:00
5 changed files with 48 additions and 44 deletions

View File

@@ -127,8 +127,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
if (!this.invokeAutoCloseable) {
this.destroyMethodNames = destroyMethodNames;
List<Method> destroyMethods = new ArrayList<>(destroyMethodNames.length);
for (int i = 0; i < destroyMethodNames.length; i++) {
String destroyMethodName = destroyMethodNames[i];
for (String destroyMethodName : destroyMethodNames) {
Method destroyMethod = determineDestroyMethod(destroyMethodName);
if (destroyMethod == null) {
if (beanDefinition.isEnforceDestroyMethod()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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,11 +20,7 @@ import org.springframework.lang.Nullable;
/**
* Handy class for wrapping checked {@code Exceptions} with a root cause.
*
* <p>This class is {@code abstract} to force the programmer to extend
* the class. {@code getMessage} will include nested exception
* information; {@code printStackTrace} and other like methods will
* delegate to the wrapped exception, if any.
* This class is {@code abstract} to force the programmer to extend the class.
*
* <p>The similarity between this class and the {@link NestedRuntimeException}
* class is unavoidable, as Java forces these two classes to have different

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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,11 +20,7 @@ import org.springframework.lang.Nullable;
/**
* Handy class for wrapping runtime {@code Exceptions} with a root cause.
*
* <p>This class is {@code abstract} to force the programmer to extend
* the class. {@code getMessage} will include nested exception
* information; {@code printStackTrace} and other like methods will
* delegate to the wrapped exception, if any.
* This class is {@code abstract} to force the programmer to extend the class.
*
* <p>The similarity between this class and the {@link NestedCheckedException}
* class is unavoidable, as Java forces these two classes to have different

View File

@@ -581,7 +581,7 @@ public class Jackson2ObjectMapperBuilder {
* @see com.fasterxml.jackson.databind.Module
*/
public Jackson2ObjectMapperBuilder modulesToInstall(Module... modules) {
this.modules = Arrays.asList(modules);
this.modules = new ArrayList<>(Arrays.asList(modules));
this.findWellKnownModules = true;
return this;
}

View File

@@ -228,26 +228,6 @@ class Jackson2ObjectMapperBuilderTests {
Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build());
}
@Test
void modules() {
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(module).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertThat(serializers.findSerializer(null, SimpleType.construct(Integer.class), null)).isSameAs(serializer1);
}
@Test
void modulesWithConsumer() {
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(list -> list.add(module) ).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertThat(serializers.findSerializer(null, SimpleType.construct(Integer.class), null)).isSameAs(serializer1);
}
@Test
void modulesToInstallByClass() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
@@ -311,14 +291,15 @@ class Jackson2ObjectMapperBuilderTests {
barModule.addSerializer(new BarSerializer());
builder.modulesToInstall(fooModule, barModule);
ObjectMapper objectMapper = builder.build();
assertThat(StreamSupport
.stream(getSerializerFactoryConfig(objectMapper).serializers().spliterator(), false)
.filter(s -> s.findSerializer(null, SimpleType.construct(Foo.class), null) != null)
.count()).isEqualTo(1);
.stream(getSerializerFactoryConfig(objectMapper).serializers().spliterator(), false)
.filter(s -> s.findSerializer(null, SimpleType.construct(Foo.class), null) != null)
.count()).isEqualTo(1);
assertThat(StreamSupport
.stream(getSerializerFactoryConfig(objectMapper).serializers().spliterator(), false)
.filter(s -> s.findSerializer(null, SimpleType.construct(Bar.class), null) != null)
.count()).isEqualTo(1);
.stream(getSerializerFactoryConfig(objectMapper).serializers().spliterator(), false)
.filter(s -> s.findSerializer(null, SimpleType.construct(Bar.class), null) != null)
.count()).isEqualTo(1);
}
private static SerializerFactoryConfig getSerializerFactoryConfig(ObjectMapper objectMapper) {
@@ -329,6 +310,38 @@ class Jackson2ObjectMapperBuilderTests {
return ((BasicDeserializerFactory) objectMapper.getDeserializationContext().getFactory()).getFactoryConfig();
}
@Test
void modules() {
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(module).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertThat(serializers.findSerializer(null, SimpleType.construct(Integer.class), null)).isSameAs(serializer1);
}
@Test
void modulesWithConsumer() {
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(list -> list.add(module) ).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertThat(serializers.findSerializer(null, SimpleType.construct(Integer.class), null)).isSameAs(serializer1);
}
@Test
void modulesWithConsumerAfterModulesToInstall() {
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modulesToInstall(new JavaTimeModule())
.modules(list -> list.add(module) ).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertThat(serializers.findSerializer(null, SimpleType.construct(Integer.class), null)).isSameAs(serializer1);
}
@Test
void propertyNamingStrategy() {
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
@@ -341,7 +354,7 @@ class Jackson2ObjectMapperBuilderTests {
void serializerByType() {
JsonSerializer<Number> serializer = new NumberSerializer(Integer.class);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.modules(new ArrayList<>()) // disable well-known modules detection
.serializerByType(Boolean.class, serializer)
.build();
assertThat(getSerializerFactoryConfig(objectMapper).hasSerializers()).isTrue();
@@ -353,7 +366,7 @@ class Jackson2ObjectMapperBuilderTests {
void deserializerByType() throws JsonMappingException {
JsonDeserializer<Date> deserializer = new DateDeserializers.DateDeserializer();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.modules(new ArrayList<>()) // disable well-known modules detection
.deserializerByType(Date.class, deserializer)
.build();
assertThat(getDeserializerFactoryConfig(objectMapper).hasDeserializers()).isTrue();
@@ -434,7 +447,7 @@ class Jackson2ObjectMapperBuilderTests {
JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class);
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.modules(new ArrayList<>()) // disable well-known modules detection
.serializers(serializer1)
.serializersByType(Collections.singletonMap(Boolean.class, serializer2))
.deserializersByType(deserializerMap)