Skip to content

Commit ce62224

Browse files
christophstroblmp911de
authored andcommitted
Add missing native image runtime hints for Jackson Page serialization.
Closes #3117 Original pull request: #3119
1 parent c90e274 commit ce62224

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java

+24
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package org.springframework.data.web.aot;
1717

18+
import org.springframework.aot.hint.MemberCategory;
1819
import org.springframework.aot.hint.RuntimeHints;
1920
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2021
import org.springframework.aot.hint.TypeReference;
22+
import org.springframework.data.web.PagedModel;
2123
import org.springframework.data.web.config.SpringDataJacksonConfiguration.PageModule;
2224
import org.springframework.lang.Nullable;
2325
import org.springframework.util.ClassUtils;
@@ -34,8 +36,30 @@ class WebRuntimeHints implements RuntimeHintsRegistrar {
3436
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3537

3638
if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader)) {
39+
40+
// Page Model for Jackson Rendering
41+
hints.reflection().registerType(org.springframework.data.web.PagedModel.class,
42+
MemberCategory.INVOKE_PUBLIC_METHODS);
43+
hints.reflection().registerType(PagedModel.PageMetadata.class, MemberCategory.INVOKE_PUBLIC_METHODS);
44+
45+
// Type that might not be seen otherwise
3746
hints.reflection().registerType(TypeReference.of("org.springframework.data.domain.Unpaged"),
3847
hint -> hint.onReachableType(PageModule.class));
48+
49+
// Jackson Converters used via @JsonSerialize in SpringDataJacksonConfiguration
50+
hints.reflection().registerType(
51+
TypeReference
52+
.of("org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PageModelConverter"),
53+
hint -> {
54+
hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS);
55+
hint.onReachableType(PageModule.class);
56+
});
57+
hints.reflection().registerType(TypeReference.of(
58+
"org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PlainPageSerializationWarning"),
59+
hint -> {
60+
hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS);
61+
hint.onReachableType(PageModule.class);
62+
});
3963
}
4064
}
4165
}

0 commit comments

Comments
 (0)