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 8b16078..8d8b781 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 @@ -3,6 +3,7 @@ package fr.pandacube.lib.core.json; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; +import com.google.gson.Strictness; import com.google.gson.ToNumberStrategy; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; @@ -74,21 +75,21 @@ public class Json { public static final Gson gson = build(Function.identity()); /** - * {@link Gson} instance with {@link GsonBuilder#setLenient()}, {@link GsonBuilder#setPrettyPrinting()} and support + * {@link Gson} instance with {@link Strictness#LENIENT}, {@link GsonBuilder#setPrettyPrinting()} and support * for Java records and additional {@link TypeAdapterFactory} provided with * {@link #registerTypeAdapterFactory(TypeAdapterFactory)}. */ public static final Gson gsonPrettyPrinting = build(GsonBuilder::setPrettyPrinting); /** - * {@link Gson} instance with {@link GsonBuilder#setLenient()}, {@link GsonBuilder#serializeNulls()} and support for + * {@link Gson} instance with {@link Strictness#LENIENT}, {@link GsonBuilder#serializeNulls()} and support for * Java records and additional {@link TypeAdapterFactory} provided with * {@link #registerTypeAdapterFactory(TypeAdapterFactory)}. */ public static final Gson gsonSerializeNulls = build(GsonBuilder::serializeNulls); /** - * {@link Gson} instance with {@link GsonBuilder#setLenient()}, {@link GsonBuilder#serializeNulls()}, + * {@link Gson} instance with {@link Strictness#LENIENT}, {@link GsonBuilder#serializeNulls()}, * {@link GsonBuilder#setPrettyPrinting()} and support for Java records and additional {@link TypeAdapterFactory} * provided with {@link #registerTypeAdapterFactory(TypeAdapterFactory)}. */ @@ -105,7 +106,7 @@ public class Json { .registerTypeAdapterFactory(new CustomAdapterFactory()) .disableHtmlEscaping() .setObjectToNumberStrategy(YAML_EQUIVALENT_NUMBER_STRATEGY) - .setLenient(); + .setStrictness(Strictness.LENIENT); return builderModifier.apply(base).create(); } diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java index 14168a0..5bb5a02 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java @@ -38,15 +38,13 @@ import java.util.Map; if (!(json instanceof JsonObject jsonObj)) throw new JsonParseException("Unable to deserialize a ConfigurationSerializable from the provided json structure."); - // the deserialized json may contain older data compatible with pre 1.21.5 but not compatible after. // if it contains both old and new data, delete the old one introduced for compatibility - if (jsonObj.has("DataVersion")) { // it uses the new DataVersion data + if (jsonObj.has("DataVersion") || jsonObj.has("id")) { jsonObj.remove("v"); - } - if (jsonObj.has("id")) { jsonObj.remove("type"); } + // format used when using ConfigurationSerialization if (jsonObj.has(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) return context.deserialize(jsonObj, ConfigurationSerializable.class); @@ -79,17 +77,7 @@ import java.util.Map; @Override public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) { - Map serialized = src.serialize(); - - // make the generated json compatible with pre 1.21.5 deserializer (temporary fix during the upgrade of the server) - if (serialized.containsKey("DataVersion")) { - serialized.put("v", serialized.get("DataVersion")); - } - if (serialized.containsKey("id")) { - serialized.put("type", Registry.MATERIAL.getOrThrow(Key.key((String)serialized.get("id"))).name()); - } - - return context.serialize(serialized, MAP_STR_OBJ_TYPE.getType()); + return context.serialize(src.serialize(), MAP_STR_OBJ_TYPE.getType()); }