Fix Gson native record support check

This commit is contained in:
Marc Baloup 2023-03-12 14:28:31 +01:00
parent b2f5770461
commit b6dba62fa4

View File

@ -1,16 +1,16 @@
package fr.pandacube.lib.core.json;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory;
import com.google.gson.internal.reflect.ReflectionHelper;
import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
* Provides pre-instanciated {@link Gson} instances, all with support for Java records and additionnal
* {@link TypeAdapterFactory} provided with {@link #registerTypeAdapterFactory(TypeAdapterFactory)}.
@ -91,12 +91,13 @@ public class Json {
private static boolean hasGsonNativeRecordSupport() {
for (Class<?> innerClasses : ReflectiveTypeAdapterFactory.class.getDeclaredClasses()) {
if (innerClasses.getSimpleName().equals("RecordAdapter"))
try {
ReflectionHelper.class.getDeclaredField("RECORD_HELPER");
return true;
}
} catch (NoSuchFieldException e) {
return false;
}
}