From f14b9a10ef4ad9c32763c807713815ea224959d8 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Tue, 22 Nov 2022 16:34:01 +0100 Subject: [PATCH] Add native serialization hints for basic Java types Resolves #4239 --- .../batch/core/aot/CoreRuntimeHints.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/aot/CoreRuntimeHints.java b/spring-batch-core/src/main/java/org/springframework/batch/core/aot/CoreRuntimeHints.java index 1163d2724b..5f74bbbfe3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/aot/CoreRuntimeHints.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/aot/CoreRuntimeHints.java @@ -16,13 +16,30 @@ package org.springframework.batch.core.aot; import java.sql.Types; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.Period; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; +import java.util.Hashtable; +import java.util.Properties; +import java.util.UUID; +import java.util.stream.Stream; import org.springframework.aop.SpringProxy; import org.springframework.aop.framework.Advised; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.SerializationHints; import org.springframework.aot.hint.TypeReference; import org.springframework.batch.core.scope.context.JobContext; import org.springframework.batch.core.scope.context.StepContext; @@ -41,6 +58,7 @@ public class CoreRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + // resource hints hints.resources().registerPattern("org/springframework/batch/core/schema-h2.sql"); hints.resources().registerPattern("org/springframework/batch/core/schema-derby.sql"); hints.resources().registerPattern("org/springframework/batch/core/schema-hsqldb.sql"); @@ -54,6 +72,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { hints.resources().registerPattern("org/springframework/batch/core/schema-sqlserver.sql"); hints.resources().registerPattern("org/springframework/batch/core/schema-sybase.sql"); + // proxy hints hints.proxies() .registerJdkProxy(builder -> builder .proxiedInterfaces(TypeReference.of("org.springframework.batch.core.repository.JobRepository")) @@ -62,12 +81,18 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { .proxiedInterfaces(TypeReference.of("org.springframework.batch.core.explore.JobExplorer")) .proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class)); + // reflection hints hints.reflection().registerType(Types.class, MemberCategory.DECLARED_FIELDS); - hints.reflection().registerType(JobContext.class, MemberCategory.INVOKE_PUBLIC_METHODS); hints.reflection().registerType(StepContext.class, MemberCategory.INVOKE_PUBLIC_METHODS); - hints.serialization().registerType(HashMap.class); + // serialization hints + SerializationHints serializationHints = hints.serialization(); + Stream.of(Number.class, Byte.class, Short.class, Integer.class, Long.class, Double.class, Float.class, + Character.class, String.class, Boolean.class, Date.class, Calendar.class, LocalDate.class, + LocalTime.class, LocalDateTime.class, OffsetTime.class, OffsetDateTime.class, ZonedDateTime.class, + Instant.class, Duration.class, Period.class, HashMap.class, Hashtable.class, ArrayList.class, + Properties.class, Exception.class, UUID.class).forEach(serializationHints::registerType); } }