From c41609d01d813a765cf04ef06ae267ac77fd7a54 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 18 Aug 2022 09:44:55 +0200 Subject: [PATCH] Polish --- .../boot/json/JacksonRuntimeHints.java | 14 +++++++++----- .../boot/logging/logback/LogbackRuntimeHints.java | 8 +------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java index 65eabe30d4..e25f848e61 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java @@ -16,7 +16,7 @@ package org.springframework.boot.json; -import java.util.stream.Stream; +import java.util.function.Consumer; import com.fasterxml.jackson.databind.ser.std.ClassSerializer; import com.fasterxml.jackson.databind.ser.std.FileSerializer; @@ -29,6 +29,8 @@ import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeHint.Builder; +import org.springframework.aot.hint.TypeReference; import org.springframework.util.ClassUtils; /** @@ -38,6 +40,9 @@ import org.springframework.util.ClassUtils; */ class JacksonRuntimeHints implements RuntimeHintsRegistrar { + private static final Consumer INVOKE_PUBLIC_CONSTRUCTORS = (hint) -> hint + .withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS); + @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { if (!ClassUtils.isPresent("com.fasterxml.jackson.databind.ser.BasicSerializerFactory", classLoader)) { @@ -47,10 +52,9 @@ class JacksonRuntimeHints implements RuntimeHintsRegistrar { } private void registerSerializers(ReflectionHints hints) { - Stream.of(AtomicBooleanSerializer.class, AtomicIntegerSerializer.class, AtomicLongSerializer.class, - FileSerializer.class, ClassSerializer.class, TokenBufferSerializer.class) - .forEach((type) -> hints.registerType(type, - (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))); + hints.registerTypes(TypeReference.listOf(AtomicBooleanSerializer.class, AtomicIntegerSerializer.class, + AtomicLongSerializer.class, FileSerializer.class, ClassSerializer.class, TokenBufferSerializer.class), + INVOKE_PUBLIC_CONSTRUCTORS); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java index 812c67f153..34b76f827d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java @@ -17,8 +17,6 @@ package org.springframework.boot.logging.logback; import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.pattern.SyslogStartConverter; @@ -73,12 +71,8 @@ class LogbackRuntimeHints implements RuntimeHintsRegistrar { } private void registerForPublicConstructorInvocation(ReflectionHints reflection, Class... classes) { - reflection.registerTypes(typeReferences(classes), + reflection.registerTypes(TypeReference.listOf(classes), (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)); } - private Iterable typeReferences(Class... classes) { - return Stream.of(classes).map(TypeReference::of).collect(Collectors.toList()); - } - }