From b6dba62fa4710b1531b95373676e5dd41064348a Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 12 Mar 2023 14:28:31 +0100 Subject: [PATCH] Fix Gson native record support check --- .../java/fr/pandacube/lib/core/json/Json.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pandalib-core/src/main/java/fr/pandacube/lib/core/json/Json.java b/pandalib-core/src/main/java/fr/pandacube/lib/core/json/Json.java index eee80b8..2bcca68 100644 --- a/pandalib-core/src/main/java/fr/pandacube/lib/core/json/Json.java +++ b/pandalib-core/src/main/java/fr/pandacube/lib/core/json/Json.java @@ -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,11 +91,12 @@ public class Json { private static boolean hasGsonNativeRecordSupport() { - for (Class innerClasses : ReflectiveTypeAdapterFactory.class.getDeclaredClasses()) { - if (innerClasses.getSimpleName().equals("RecordAdapter")) - return true; + try { + ReflectionHelper.class.getDeclaredField("RECORD_HELPER"); + return true; + } catch (NoSuchFieldException e) { + return false; } - return false; }