[gson] Fix tests

This commit is contained in:
Johannes Frohnmeyer 2022-09-25 12:07:03 +02:00
parent a8ab56c9f4
commit 5dd5926cb6
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 10 additions and 21 deletions

View File

@ -1,32 +1,30 @@
package io.gitlab.jfronny.commons.serialize.gson.api;
import io.gitlab.jfronny.commons.serialize.*;
import io.gitlab.jfronny.commons.serialize.gson.impl.*;
import com.google.gson.*;
import io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolders;
import java.lang.reflect.*;
import java.util.function.*;
import java.lang.reflect.Type;
import java.util.function.Consumer;
@Deprecated
public class GsonHolder {
private static final io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolder BACKEND = new io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolder();
public static Gson getGson() {
return BACKEND.getGson();
return GsonHolders.API.getGson();
}
public static void registerTypeAdapter(Type type, Object typeAdapter) {
BACKEND.registerTypeAdapter(type, typeAdapter);
GsonHolders.registerTypeAdapter(type, typeAdapter);
}
public static void registerTypeAdapterFactory(TypeAdapterFactory factory) {
BACKEND.registerTypeAdapterFactory(factory);
GsonHolders.registerTypeAdapterFactory(factory);
}
public static void modifyBuilder(Consumer<GsonBuilder> func) {
BACKEND.modifyBuilder(func);
GsonHolders.API.modifyBuilder(func);
}
public static void register() {
Serializer.setInstance(new GsonHolderSerializer(BACKEND));
GsonHolders.registerSerializer();
}
}

View File

@ -20,17 +20,8 @@ public class GsonTest {
@Test
void gsonIgnore() throws IOException {
assertEquals("null", Serializer.getInstance().serialize(new ExampleTypeHidden()));
assertEquals("""
{
"shouldShow": "Yes"
}""", Serializer.getInstance().serialize(new TransitiveHiddenType()));
assertEquals("""
{
"id": "Yes",
"shown": {
"shouldShow": "Yes"
}
}""", Serializer.getInstance().serialize(new ExampleType()));
assertEquals("{\"shouldShow\":\"Yes\"}", Serializer.getInstance().serialize(new TransitiveHiddenType()));
assertEquals("{\"id\":\"Yes\",\"shown\":{\"shouldShow\":\"Yes\"}}", Serializer.getInstance().serialize(new ExampleType()));
}
@Test