From fdfcb51123f5117778b7b2f5eb201e02690a31bf Mon Sep 17 00:00:00 2001 From: JFronny Date: Sun, 25 Sep 2022 12:22:17 +0200 Subject: [PATCH] [gson] Add GsonHolders.modifyBuilder --- .../commons/serialize/gson/api/GsonHolder.java | 2 +- .../commons/serialize/gson/api/v1/GsonHolders.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/GsonHolder.java b/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/GsonHolder.java index 850aeb3..dcca896 100644 --- a/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/GsonHolder.java +++ b/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/GsonHolder.java @@ -21,7 +21,7 @@ public class GsonHolder { } public static void modifyBuilder(Consumer func) { - GsonHolders.API.modifyBuilder(func); + GsonHolders.modifyBuilder(func); } public static void register() { diff --git a/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/v1/GsonHolders.java b/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/v1/GsonHolders.java index c51dfbb..1467618 100644 --- a/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/v1/GsonHolders.java +++ b/commons-gson/src/main/java/io/gitlab/jfronny/commons/serialize/gson/api/v1/GsonHolders.java @@ -27,16 +27,17 @@ public class GsonHolders { ); public static void registerTypeAdapter(Type type, Object typeAdapter) { - synchronized (KNOWN_INSTANCES) { - KNOWN_MODIFICATIONS.add(b -> b.registerTypeAdapter(type, typeAdapter)); - for (GsonHolder holder : KNOWN_INSTANCES) holder.registerTypeAdapter(type, typeAdapter); - } + modifyBuilder(b -> b.registerTypeAdapter(type, typeAdapter)); } public static void registerTypeAdapterFactory(TypeAdapterFactory factory) { + modifyBuilder(b -> b.registerTypeAdapterFactory(factory)); + } + + public static void modifyBuilder(Consumer func) { synchronized (KNOWN_INSTANCES) { - KNOWN_MODIFICATIONS.add(b -> b.registerTypeAdapterFactory(factory)); - for (GsonHolder holder : KNOWN_INSTANCES) holder.registerTypeAdapterFactory(factory); + KNOWN_MODIFICATIONS.add(func); + for (GsonHolder holder : KNOWN_INSTANCES) holder.modifyBuilder(func); } }