Add classpath checks to JacksonModulesRuntimeHints
Closes gh-29001
This commit is contained in:
parent
5525b17f19
commit
0973348bde
|
@ -21,6 +21,7 @@ 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.TypeReference;
|
import org.springframework.aot.hint.TypeReference;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link RuntimeHintsRegistrar} implementation that registers reflection entries
|
* {@link RuntimeHintsRegistrar} implementation that registers reflection entries
|
||||||
|
@ -34,14 +35,16 @@ class JacksonModulesRuntimeHints implements RuntimeHintsRegistrar {
|
||||||
@Override
|
@Override
|
||||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||||
ReflectionHints reflectionHints = hints.reflection();
|
ReflectionHints reflectionHints = hints.reflection();
|
||||||
registerType(reflectionHints, "com.fasterxml.jackson.datatype.jdk8.Jdk8Module");
|
registerType(reflectionHints, "com.fasterxml.jackson.datatype.jdk8.Jdk8Module", classLoader);
|
||||||
registerType(reflectionHints, "com.fasterxml.jackson.datatype.jsr310.JavaTimeModule");
|
registerType(reflectionHints, "com.fasterxml.jackson.datatype.jsr310.JavaTimeModule", classLoader);
|
||||||
registerType(reflectionHints, "com.fasterxml.jackson.module.kotlin.KotlinModule");
|
registerType(reflectionHints, "com.fasterxml.jackson.module.kotlin.KotlinModule", classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerType(ReflectionHints reflectionHints, String className) {
|
private void registerType(ReflectionHints reflectionHints, String className, ClassLoader classLoader) {
|
||||||
reflectionHints.registerType(TypeReference.of(className),
|
if (ClassUtils.isPresent(className, classLoader)) {
|
||||||
builder -> builder.onReachableType(TypeReference.of(Jackson2ObjectMapperBuilder.class))
|
reflectionHints.registerType(TypeReference.of(className),
|
||||||
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
builder -> builder.onReachableType(TypeReference.of(Jackson2ObjectMapperBuilder.class))
|
||||||
|
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue