Skip to content

Commit f14b9a1

Browse files
committed
Add native serialization hints for basic Java types
Resolves #4239
1 parent dfbc3d0 commit f14b9a1

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/aot/CoreRuntimeHints.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,30 @@
1616
package org.springframework.batch.core.aot;
1717

1818
import java.sql.Types;
19+
import java.time.Duration;
20+
import java.time.Instant;
21+
import java.time.LocalDate;
22+
import java.time.LocalDateTime;
23+
import java.time.LocalTime;
24+
import java.time.OffsetDateTime;
25+
import java.time.OffsetTime;
26+
import java.time.Period;
27+
import java.time.ZonedDateTime;
28+
import java.util.ArrayList;
29+
import java.util.Calendar;
30+
import java.util.Date;
1931
import java.util.HashMap;
32+
import java.util.Hashtable;
33+
import java.util.Properties;
34+
import java.util.UUID;
35+
import java.util.stream.Stream;
2036

2137
import org.springframework.aop.SpringProxy;
2238
import org.springframework.aop.framework.Advised;
2339
import org.springframework.aot.hint.MemberCategory;
2440
import org.springframework.aot.hint.RuntimeHints;
2541
import org.springframework.aot.hint.RuntimeHintsRegistrar;
42+
import org.springframework.aot.hint.SerializationHints;
2643
import org.springframework.aot.hint.TypeReference;
2744
import org.springframework.batch.core.scope.context.JobContext;
2845
import org.springframework.batch.core.scope.context.StepContext;
@@ -41,6 +58,7 @@ public class CoreRuntimeHints implements RuntimeHintsRegistrar {
4158
@Override
4259
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
4360

61+
// resource hints
4462
hints.resources().registerPattern("org/springframework/batch/core/schema-h2.sql");
4563
hints.resources().registerPattern("org/springframework/batch/core/schema-derby.sql");
4664
hints.resources().registerPattern("org/springframework/batch/core/schema-hsqldb.sql");
@@ -54,6 +72,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
5472
hints.resources().registerPattern("org/springframework/batch/core/schema-sqlserver.sql");
5573
hints.resources().registerPattern("org/springframework/batch/core/schema-sybase.sql");
5674

75+
// proxy hints
5776
hints.proxies()
5877
.registerJdkProxy(builder -> builder
5978
.proxiedInterfaces(TypeReference.of("org.springframework.batch.core.repository.JobRepository"))
@@ -62,12 +81,18 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
6281
.proxiedInterfaces(TypeReference.of("org.springframework.batch.core.explore.JobExplorer"))
6382
.proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class));
6483

84+
// reflection hints
6585
hints.reflection().registerType(Types.class, MemberCategory.DECLARED_FIELDS);
66-
6786
hints.reflection().registerType(JobContext.class, MemberCategory.INVOKE_PUBLIC_METHODS);
6887
hints.reflection().registerType(StepContext.class, MemberCategory.INVOKE_PUBLIC_METHODS);
6988

70-
hints.serialization().registerType(HashMap.class);
89+
// serialization hints
90+
SerializationHints serializationHints = hints.serialization();
91+
Stream.of(Number.class, Byte.class, Short.class, Integer.class, Long.class, Double.class, Float.class,
92+
Character.class, String.class, Boolean.class, Date.class, Calendar.class, LocalDate.class,
93+
LocalTime.class, LocalDateTime.class, OffsetTime.class, OffsetDateTime.class, ZonedDateTime.class,
94+
Instant.class, Duration.class, Period.class, HashMap.class, Hashtable.class, ArrayList.class,
95+
Properties.class, Exception.class, UUID.class).forEach(serializationHints::registerType);
7196
}
7297

7398
}

0 commit comments

Comments
 (0)