[gson] Add GsonHolders.modifyBuilder

This commit is contained in:
Johannes Frohnmeyer 2022-09-25 12:22:17 +02:00
parent 5dd5926cb6
commit fdfcb51123
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 8 additions and 7 deletions

View File

@ -21,7 +21,7 @@ public class GsonHolder {
}
public static void modifyBuilder(Consumer<GsonBuilder> func) {
GsonHolders.API.modifyBuilder(func);
GsonHolders.modifyBuilder(func);
}
public static void register() {

View File

@ -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<GsonBuilder> 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);
}
}