pull/32123/head
Stephane Nicoll 2 years ago
parent 9630f853be
commit c41609d01d

@ -16,7 +16,7 @@
package org.springframework.boot.json; 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.ClassSerializer;
import com.fasterxml.jackson.databind.ser.std.FileSerializer; 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.ReflectionHints;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint.Builder;
import org.springframework.aot.hint.TypeReference;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
@ -38,6 +40,9 @@ import org.springframework.util.ClassUtils;
*/ */
class JacksonRuntimeHints implements RuntimeHintsRegistrar { class JacksonRuntimeHints implements RuntimeHintsRegistrar {
private static final Consumer<Builder> INVOKE_PUBLIC_CONSTRUCTORS = (hint) -> hint
.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
@Override @Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
if (!ClassUtils.isPresent("com.fasterxml.jackson.databind.ser.BasicSerializerFactory", classLoader)) { if (!ClassUtils.isPresent("com.fasterxml.jackson.databind.ser.BasicSerializerFactory", classLoader)) {
@ -47,10 +52,9 @@ class JacksonRuntimeHints implements RuntimeHintsRegistrar {
} }
private void registerSerializers(ReflectionHints hints) { private void registerSerializers(ReflectionHints hints) {
Stream.of(AtomicBooleanSerializer.class, AtomicIntegerSerializer.class, AtomicLongSerializer.class, hints.registerTypes(TypeReference.listOf(AtomicBooleanSerializer.class, AtomicIntegerSerializer.class,
FileSerializer.class, ClassSerializer.class, TokenBufferSerializer.class) AtomicLongSerializer.class, FileSerializer.class, ClassSerializer.class, TokenBufferSerializer.class),
.forEach((type) -> hints.registerType(type, INVOKE_PUBLIC_CONSTRUCTORS);
(hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)));
} }
} }

@ -17,8 +17,6 @@
package org.springframework.boot.logging.logback; package org.springframework.boot.logging.logback;
import java.util.function.Consumer; 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.LoggerContext;
import ch.qos.logback.classic.pattern.SyslogStartConverter; import ch.qos.logback.classic.pattern.SyslogStartConverter;
@ -73,12 +71,8 @@ class LogbackRuntimeHints implements RuntimeHintsRegistrar {
} }
private void registerForPublicConstructorInvocation(ReflectionHints reflection, Class<?>... classes) { private void registerForPublicConstructorInvocation(ReflectionHints reflection, Class<?>... classes) {
reflection.registerTypes(typeReferences(classes), reflection.registerTypes(TypeReference.listOf(classes),
(hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)); (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
} }
private Iterable<TypeReference> typeReferences(Class<?>... classes) {
return Stream.of(classes).map(TypeReference::of).collect(Collectors.toList());
}
} }

Loading…
Cancel
Save