Skip to content

Commit

Permalink
Fix ut
Browse files Browse the repository at this point in the history
Signed-off-by: crazyhzm <[email protected]>
  • Loading branch information
CrazyHZM committed Feb 4, 2024
1 parent 806aba4 commit 404c5ed
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@

public class AotUtils {

private static final Set<Class<?>> serializationTypeCache = new LinkedHashSet<>();

private AotUtils() {}

public static void registerSerializationForService(Class<?> serviceType, RuntimeHints hints) {
Set<Class<?>> serializationTypeCache = new LinkedHashSet<>();
Arrays.stream(serviceType.getMethods()).forEach((method) -> {
Arrays.stream(method.getParameterTypes())
.forEach((parameterType) -> registerSerializationType(parameterType, hints));
.forEach(
(parameterType) -> registerSerializationType(parameterType, hints, serializationTypeCache));

registerSerializationType(method.getReturnType(), hints);
registerSerializationType(method.getReturnType(), hints, serializationTypeCache);
});
}

private static void registerSerializationType(Class<?> registerType, RuntimeHints hints) {
private static void registerSerializationType(
Class<?> registerType, RuntimeHints hints, Set<Class<?>> serializationTypeCache) {
if (isPrimitive(registerType)) {
hints.serialization().registerType(TypeReference.of(ClassUtils.getBoxedClass(registerType)));
serializationTypeCache.add(registerType);
Expand All @@ -53,12 +54,12 @@ private static void registerSerializationType(Class<?> registerType, RuntimeHint

Arrays.stream(registerType.getDeclaredFields()).forEach((field -> {
if (!serializationTypeCache.contains(field.getType())) {
registerSerializationType(field.getType(), hints);
registerSerializationType(field.getType(), hints, serializationTypeCache);
serializationTypeCache.add(field.getType());
}
}));

registerSerializationType(registerType.getSuperclass(), hints);
registerSerializationType(registerType.getSuperclass(), hints, serializationTypeCache);
}
}
}
Expand Down

0 comments on commit 404c5ed

Please sign in to comment.