|
16 | 16 |
|
17 | 17 | package org.springframework.http.converter.json; |
18 | 18 |
|
| 19 | +import java.util.function.Consumer; |
| 20 | + |
19 | 21 | import org.springframework.aot.hint.MemberCategory; |
20 | | -import org.springframework.aot.hint.ReflectionHints; |
21 | 22 | import org.springframework.aot.hint.RuntimeHints; |
22 | 23 | import org.springframework.aot.hint.RuntimeHintsRegistrar; |
| 24 | +import org.springframework.aot.hint.TypeHint.Builder; |
23 | 25 | import org.springframework.aot.hint.TypeReference; |
24 | 26 |
|
25 | 27 | /** |
26 | 28 | * {@link RuntimeHintsRegistrar} implementation that registers reflection entries |
27 | 29 | * for {@link Jackson2ObjectMapperBuilder} well-known modules. |
28 | 30 | * |
29 | 31 | * @author Sebastien Deleuze |
| 32 | + * @author Stephane Nicoll |
30 | 33 | * @since 6.0 |
31 | 34 | */ |
32 | 35 | class JacksonModulesRuntimeHints implements RuntimeHintsRegistrar { |
33 | 36 |
|
| 37 | + private static final Consumer<Builder> asJacksonModule = builder -> |
| 38 | + builder.onReachableType(TypeReference.of(Jackson2ObjectMapperBuilder.class)) |
| 39 | + .withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); |
| 40 | + |
34 | 41 | @Override |
35 | 42 | public void registerHints(RuntimeHints hints, ClassLoader classLoader) { |
36 | | - ReflectionHints reflectionHints = hints.reflection(); |
37 | | - registerType(reflectionHints, "com.fasterxml.jackson.datatype.jdk8.Jdk8Module", classLoader); |
38 | | - registerType(reflectionHints, "com.fasterxml.jackson.datatype.jsr310.JavaTimeModule", classLoader); |
39 | | - registerType(reflectionHints, "com.fasterxml.jackson.module.kotlin.KotlinModule", classLoader); |
| 43 | + hints.reflection() |
| 44 | + .registerTypeIfPresent(classLoader, |
| 45 | + "com.fasterxml.jackson.datatype.jdk8.Jdk8Module", asJacksonModule) |
| 46 | + .registerTypeIfPresent(classLoader, |
| 47 | + "com.fasterxml.jackson.datatype.jsr310.JavaTimeModule", asJacksonModule) |
| 48 | + .registerTypeIfPresent(classLoader, |
| 49 | + "com.fasterxml.jackson.module.kotlin.KotlinModule", asJacksonModule); |
40 | 50 | } |
41 | 51 |
|
42 | | - private void registerType(ReflectionHints reflectionHints, String className, ClassLoader classLoader) { |
43 | | - reflectionHints.registerTypeIfPresent(classLoader, className, |
44 | | - builder -> builder.onReachableType(TypeReference.of(Jackson2ObjectMapperBuilder.class)) |
45 | | - .withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); |
46 | | - } |
47 | 52 | } |
0 commit comments