From ce62224c17c1a77e9205d6ecf6a978770200065b Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Wed, 3 Jul 2024 09:09:21 +0200 Subject: [PATCH] Add missing native image runtime hints for Jackson Page serialization. Closes #3117 Original pull request: #3119 --- .../data/web/aot/WebRuntimeHints.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java b/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java index f791ce4981..3a9aee614b 100644 --- a/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java +++ b/src/main/java/org/springframework/data/web/aot/WebRuntimeHints.java @@ -15,9 +15,11 @@ */ package org.springframework.data.web.aot; +import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; +import org.springframework.data.web.PagedModel; import org.springframework.data.web.config.SpringDataJacksonConfiguration.PageModule; import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; @@ -34,8 +36,30 @@ class WebRuntimeHints implements RuntimeHintsRegistrar { public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader)) { + + // Page Model for Jackson Rendering + hints.reflection().registerType(org.springframework.data.web.PagedModel.class, + MemberCategory.INVOKE_PUBLIC_METHODS); + hints.reflection().registerType(PagedModel.PageMetadata.class, MemberCategory.INVOKE_PUBLIC_METHODS); + + // Type that might not be seen otherwise hints.reflection().registerType(TypeReference.of("org.springframework.data.domain.Unpaged"), hint -> hint.onReachableType(PageModule.class)); + + // Jackson Converters used via @JsonSerialize in SpringDataJacksonConfiguration + hints.reflection().registerType( + TypeReference + .of("org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PageModelConverter"), + hint -> { + hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS); + hint.onReachableType(PageModule.class); + }); + hints.reflection().registerType(TypeReference.of( + "org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PlainPageSerializationWarning"), + hint -> { + hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS); + hint.onReachableType(PageModule.class); + }); } } }