diff --git a/api-v3/src/main/java/ru/easydonate/easydonate4j/api/v3/client/SimpleEasyDonateClient.java b/api-v3/src/main/java/ru/easydonate/easydonate4j/api/v3/client/SimpleEasyDonateClient.java index 5737639..96c0a2c 100644 --- a/api-v3/src/main/java/ru/easydonate/easydonate4j/api/v3/client/SimpleEasyDonateClient.java +++ b/api-v3/src/main/java/ru/easydonate/easydonate4j/api/v3/client/SimpleEasyDonateClient.java @@ -88,10 +88,7 @@ protected SimpleEasyDonateClient( .create(); this.jsonSerialization = ModuleRegistrator.jsonSerializationService(); - this.jsonSerialization.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_SHOP_MODELS); - this.jsonSerialization.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_SHOP_RESPONSES); - this.jsonSerialization.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_PLUGIN_MODELS); - this.jsonSerialization.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_PLUGIN_RESPONSES); + this.jsonSerialization.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_MODELS); } @Override diff --git a/core/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/JsonModelsGroup.java b/core/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/JsonModelsGroup.java index c44986e..dd7ccad 100644 --- a/core/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/JsonModelsGroup.java +++ b/core/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/JsonModelsGroup.java @@ -2,10 +2,7 @@ public enum JsonModelsGroup { - API_V3_SHOP_MODELS, - API_V3_SHOP_RESPONSES, - API_V3_PLUGIN_MODELS, - API_V3_PLUGIN_RESPONSES, + API_V3_MODELS, CALLBACK_API_MODELS } diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/gson/shop/purchase/DiscountsModel.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/gson/shop/purchase/DiscountsModel.java index e9a68fb..18d26a8 100644 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/gson/shop/purchase/DiscountsModel.java +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/gson/shop/purchase/DiscountsModel.java @@ -1,13 +1,17 @@ package ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.purchase; +import com.google.gson.*; import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import ru.easydonate.easydonate4j.api.v3.data.model.shop.purchase.CouponDiscount; import ru.easydonate.easydonate4j.api.v3.data.model.shop.purchase.Discounts; import ru.easydonate.easydonate4j.api.v3.data.model.shop.purchase.MassSaleDiscount; import ru.easydonate.easydonate4j.json.serialization.Implementing; import ru.easydonate.easydonate4j.util.Wrapper; +import java.lang.reflect.Type; import java.util.Objects; import java.util.Optional; @@ -19,6 +23,10 @@ public class DiscountsModel implements Discounts { @SerializedName("coupon") private CouponDiscount usedCoupon; + public static @NotNull DiscountsArrayDeserializer getDeserializer(@NotNull Gson unsafeGsonInstance) { + return new DiscountsArrayDeserializer(unsafeGsonInstance); + } + @Override public @NotNull Optional getActiveMassSale() { return Wrapper.wrapNullable(activeMassSale); @@ -52,4 +60,23 @@ public int hashCode() { '}'; } + @AllArgsConstructor + private static final class DiscountsArrayDeserializer implements JsonDeserializer { + + private final Gson unsafeGsonInstance; + + @Override + public @Nullable DiscountsModel deserialize( + @Nullable JsonElement json, + @NotNull Type type, + @NotNull JsonDeserializationContext context + ) throws JsonParseException { + if(json == null || json.isJsonNull() || json.isJsonArray()) + return null; + + return unsafeGsonInstance.fromJson(json, type); + } + + } + } diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/gson/purchase/DiscountsModel.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/gson/purchase/DiscountsModel.java index 4824715..8dba598 100644 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/gson/purchase/DiscountsModel.java +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/gson/purchase/DiscountsModel.java @@ -1,13 +1,17 @@ package ru.easydonate.easydonate4j.callback.data.model.gson.purchase; +import com.google.gson.*; import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import ru.easydonate.easydonate4j.callback.data.model.purchase.CouponDiscount; import ru.easydonate.easydonate4j.callback.data.model.purchase.Discounts; import ru.easydonate.easydonate4j.callback.data.model.purchase.MassSaleDiscount; import ru.easydonate.easydonate4j.json.serialization.Implementing; import ru.easydonate.easydonate4j.util.Wrapper; +import java.lang.reflect.Type; import java.util.Objects; import java.util.Optional; @@ -19,6 +23,10 @@ public class DiscountsModel implements Discounts { @SerializedName("coupon") private CouponDiscount usedCoupon; + public static @NotNull DiscountsArrayDeserializer getDeserializer(@NotNull Gson unsafeGsonInstance) { + return new DiscountsArrayDeserializer(unsafeGsonInstance); + } + @Override public @NotNull Optional getActiveMassSale() { return Wrapper.wrapNullable(activeMassSale); @@ -52,4 +60,23 @@ public int hashCode() { '}'; } + @AllArgsConstructor + private static final class DiscountsArrayDeserializer implements JsonDeserializer { + + private final Gson unsafeGsonInstance; + + @Override + public @Nullable DiscountsModel deserialize( + @Nullable JsonElement json, + @NotNull Type type, + @NotNull JsonDeserializationContext context + ) throws JsonParseException { + if(json == null || json.isJsonNull() || json.isJsonArray()) + return null; + + return unsafeGsonInstance.fromJson(json, type); + } + + } + } diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/GsonSerializationService.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/GsonSerializationService.java index 1093966..a23eb47 100644 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/GsonSerializationService.java +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/GsonSerializationService.java @@ -6,19 +6,16 @@ import com.google.gson.TypeAdapterFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.purchase.DiscountsModel; import ru.easydonate.easydonate4j.exception.JsonSerializationException; import ru.easydonate.easydonate4j.json.serialization.deserializer.gson.BooleanIntDeserializer; -import ru.easydonate.easydonate4j.json.serialization.deserializer.gson.DiscountsArrayDeserializer; import ru.easydonate.easydonate4j.json.serialization.deserializer.gson.LocalDateTimeAdapter; import ru.easydonate.easydonate4j.json.serialization.exclusion.GsonDeserializationExclusionStrategy; import ru.easydonate.easydonate4j.json.serialization.exclusion.GsonSerializationExclusionStrategy; +import ru.easydonate.easydonate4j.json.serialization.failsafe.gson.ApiV3FailsafeModule; +import ru.easydonate.easydonate4j.json.serialization.failsafe.gson.CallbackApiFailsafeModule; import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson.PluginModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson.PluginResponsesRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson.ShopModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson.ShopResponsesRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.callback.gson.CallbackApiModelsRegistry; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.gson.ApiV3ModelsRegistry; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.gson.CallbackApiModelsRegistry; import ru.easydonate.easydonate4j.module.ModuleAlreadyRegisteredException; import ru.easydonate.easydonate4j.module.ModuleRegistrator; import ru.easydonate.easydonate4j.module.ModuleType; @@ -27,15 +24,19 @@ public final class GsonSerializationService extends AbstractJsonSerializationService { - private final Gson defaultGson; - private final Gson prettyGson; + private final GsonBuilder defaultGsonBuilder; + private final GsonBuilder prettyGsonBuilder; + private final Gson unsafeGsonInstance; + + private Gson defaultGson; + private Gson prettyGson; public GsonSerializationService() { TypeAdapterFactory typeAdapterFactory = new GsonTypeAdapterResolver(this); - - Gson unsafeGsonInstance = createGsonBuilder(typeAdapterFactory, null).create(); - this.defaultGson = createGsonBuilder(typeAdapterFactory, unsafeGsonInstance).create(); - this.prettyGson = createGsonBuilder(typeAdapterFactory, unsafeGsonInstance).setPrettyPrinting().create(); + this.defaultGsonBuilder = createGsonBuilder(typeAdapterFactory); + this.prettyGsonBuilder = createGsonBuilder(typeAdapterFactory).setPrettyPrinting(); + this.unsafeGsonInstance = createGsonBuilder(typeAdapterFactory).create(); + updateGsonInstances(); } public static void register() throws ModuleAlreadyRegisteredException { @@ -62,20 +63,15 @@ public static boolean isRegistered() { @Override public void registerImplementationAliasesGroup(@NotNull JsonModelsGroup jsonModelsGroup) { switch (jsonModelsGroup) { - case API_V3_SHOP_MODELS: - registerModelsGroup(jsonModelsGroup, ShopModelsRegistry.getSingleton()); - break; - case API_V3_SHOP_RESPONSES: - registerModelsGroup(jsonModelsGroup, ShopResponsesRegistry.getSingleton()); - break; - case API_V3_PLUGIN_MODELS: - registerModelsGroup(jsonModelsGroup, PluginModelsRegistry.getSingleton()); - break; - case API_V3_PLUGIN_RESPONSES: - registerModelsGroup(jsonModelsGroup, PluginResponsesRegistry.getSingleton()); + case API_V3_MODELS: + registerModelsGroup(jsonModelsGroup, ApiV3ModelsRegistry.getSingleton()); + new ApiV3FailsafeModule(unsafeGsonInstance).register(defaultGsonBuilder, prettyGsonBuilder); + updateGsonInstances(); break; case CALLBACK_API_MODELS: registerModelsGroup(jsonModelsGroup, CallbackApiModelsRegistry.getSingleton()); + new CallbackApiFailsafeModule(unsafeGsonInstance).register(defaultGsonBuilder, prettyGsonBuilder); + updateGsonInstances(); break; default: throw new IllegalArgumentException(String.format("An unexpected json models group received: %s!", jsonModelsGroup)); @@ -109,7 +105,12 @@ public void registerImplementationAliasesGroup(@NotNull JsonModelsGroup json } } - private @NotNull GsonBuilder createGsonBuilder(@NotNull TypeAdapterFactory typeAdapterFactory, @Nullable Gson unsafeGsonInstance) { + private void updateGsonInstances() { + this.defaultGson = defaultGsonBuilder.create(); + this.prettyGson = prettyGsonBuilder.create(); + } + + private @NotNull GsonBuilder createGsonBuilder(@NotNull TypeAdapterFactory typeAdapterFactory) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.serializeNulls(); @@ -121,11 +122,6 @@ public void registerImplementationAliasesGroup(@NotNull JsonModelsGroup json gsonBuilder.registerTypeAdapter(boolean.class, BooleanIntDeserializer.getSingleton()); gsonBuilder.registerTypeAdapter(LocalDateTime.class, LocalDateTimeAdapter.getSingleton()); - if(unsafeGsonInstance != null) { - // Bug [12.01.22]: some payment objects has an empty array instead of `null` for the `sales` field - gsonBuilder.registerTypeAdapter(DiscountsModel.class, new DiscountsArrayDeserializer(unsafeGsonInstance)); - } - gsonBuilder.registerTypeAdapterFactory(typeAdapterFactory); return gsonBuilder; } diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/deserializer/gson/DiscountsArrayDeserializer.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/deserializer/gson/DiscountsArrayDeserializer.java deleted file mode 100644 index b29601e..0000000 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/deserializer/gson/DiscountsArrayDeserializer.java +++ /dev/null @@ -1,28 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.deserializer.gson; - -import com.google.gson.*; -import lombok.AllArgsConstructor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.purchase.DiscountsModel; - -import java.lang.reflect.Type; - -@AllArgsConstructor -public final class DiscountsArrayDeserializer implements JsonDeserializer { - - private final Gson unsafeGsonInstance; - - @Override - public @Nullable DiscountsModel deserialize( - @Nullable JsonElement json, - @NotNull Type type, - @NotNull JsonDeserializationContext context - ) throws JsonParseException { - if(json == null || json.isJsonNull() || json.isJsonArray()) - return null; - - return unsafeGsonInstance.fromJson(json, type); - } - -} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/ApiV3FailsafeModule.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/ApiV3FailsafeModule.java new file mode 100644 index 0000000..204ecca --- /dev/null +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/ApiV3FailsafeModule.java @@ -0,0 +1,14 @@ +package ru.easydonate.easydonate4j.json.serialization.failsafe.gson; + +import com.google.gson.Gson; +import org.jetbrains.annotations.NotNull; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.purchase.DiscountsModel; + +public final class ApiV3FailsafeModule extends GsonFailsafeModule { + + public ApiV3FailsafeModule(@NotNull Gson unsafeGsonInstance) { + // Bug [12.01.22]: some payment objects has an empty array instead of `null` for the `sales` field + super.registerTypeAdapter(DiscountsModel.class, DiscountsModel.getDeserializer(unsafeGsonInstance)); + } + +} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/CallbackApiFailsafeModule.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/CallbackApiFailsafeModule.java new file mode 100644 index 0000000..85d2b26 --- /dev/null +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/CallbackApiFailsafeModule.java @@ -0,0 +1,14 @@ +package ru.easydonate.easydonate4j.json.serialization.failsafe.gson; + +import com.google.gson.Gson; +import org.jetbrains.annotations.NotNull; +import ru.easydonate.easydonate4j.callback.data.model.gson.purchase.DiscountsModel; + +public final class CallbackApiFailsafeModule extends GsonFailsafeModule { + + public CallbackApiFailsafeModule(@NotNull Gson unsafeGsonInstance) { + // Bug [12.01.22]: some payment objects has an empty array instead of `null` for the `sales` field + super.registerTypeAdapter(DiscountsModel.class, DiscountsModel.getDeserializer(unsafeGsonInstance)); + } + +} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/GsonFailsafeModule.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/GsonFailsafeModule.java new file mode 100644 index 0000000..5747000 --- /dev/null +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/gson/GsonFailsafeModule.java @@ -0,0 +1,27 @@ +package ru.easydonate.easydonate4j.json.serialization.failsafe.gson; + +import com.google.gson.GsonBuilder; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; +import java.util.Map; + +public abstract class GsonFailsafeModule { + + protected final Map typeAdapters; + + protected GsonFailsafeModule() { + this.typeAdapters = new LinkedHashMap<>(); + } + + protected void registerTypeAdapter(@NotNull Type type, @NotNull Object typeAdapter) { + typeAdapters.put(type, typeAdapter); + } + + public void register(@NotNull GsonBuilder... gsonBuilders) { + for(GsonBuilder gsonBuilder : gsonBuilders) + typeAdapters.forEach(gsonBuilder::registerTypeAdapter); + } + +} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/PluginModelsRegistry.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/PluginModelsRegistry.java deleted file mode 100644 index d20e2de..0000000 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/PluginModelsRegistry.java +++ /dev/null @@ -1,45 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.discord.widget.DiscordWidgetPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.custom.messages.CustomMessagesPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.last.payments.LastPaymentsPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.surcharge.SurchargeDiscountModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.surcharge.SurchargeDiscountsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.surcharge.SurchargePluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.vkontakte.community.widget.VKCommunityWidgetPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.vkontakte.messages.widget.VKMessagesWidgetPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.vkontakte.news.VKNewsPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.yandex.metrika.YandexMetrikaPluginSettingsModel; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class PluginModelsRegistry extends AbstractJsonModelsRegistry { - - private static final PluginModelsRegistry SINGLETON = new PluginModelsRegistry(); - - public PluginModelsRegistry() { - super(JsonModelsGroup.API_V3_PLUGIN_MODELS); - } - - public static @NotNull PluginModelsRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - SurchargePluginSettingsModel.class, - SurchargeDiscountModel.class, - SurchargeDiscountsListModel.class, - LastPaymentsPluginSettingsModel.class, - CustomMessagesPluginSettingsModel.class, - DiscordWidgetPluginSettingsModel.class, - VKCommunityWidgetPluginSettingsModel.class, - VKMessagesWidgetPluginSettingsModel.class, - VKNewsPluginSettingsModel.class, - YandexMetrikaPluginSettingsModel.class - ); - } - -} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/PluginResponsesRegistry.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/PluginResponsesRegistry.java deleted file mode 100644 index 2dc91f6..0000000 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/PluginResponsesRegistry.java +++ /dev/null @@ -1,55 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.discord.widget.GsonDiscordWidgetGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.discord.widget.GsonDiscordWidgetGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.custom.messages.GsonCustomMessagesGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.last.payments.GsonLastPaymentsGetPaymentsListResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.last.payments.GsonLastPaymentsGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.surcharge.GsonSurchargeGetDiscountResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.surcharge.GsonSurchargeGetDiscountsListResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.surcharge.GsonSurchargeGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.community.widget.GsonVKCommunityWidgetGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.community.widget.GsonVKCommunityWidgetGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.messages.widget.GsonVKMessagesWidgetGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.messages.widget.GsonVKMessagesWidgetGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.news.GsonVKNewsGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.yandex.metrika.GsonYandexMetrikaGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.yandex.metrika.GsonYandexMetrikaGetSettingsResponse; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class PluginResponsesRegistry extends AbstractJsonModelsRegistry { - - private static final PluginResponsesRegistry SINGLETON = new PluginResponsesRegistry(); - - public PluginResponsesRegistry() { - super(JsonModelsGroup.API_V3_PLUGIN_RESPONSES); - } - - public static @NotNull PluginResponsesRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - GsonSurchargeGetSettingsResponse.class, - GsonSurchargeGetDiscountResponse.class, - GsonSurchargeGetDiscountsListResponse.class, - GsonLastPaymentsGetSettingsResponse.class, - GsonLastPaymentsGetPaymentsListResponse.class, - GsonCustomMessagesGetSettingsResponse.class, - GsonDiscordWidgetGetSettingsResponse.class, - GsonDiscordWidgetGetEmbedResponse.class, - GsonVKCommunityWidgetGetSettingsResponse.class, - GsonVKCommunityWidgetGetEmbedResponse.class, - GsonVKMessagesWidgetGetSettingsResponse.class, - GsonVKMessagesWidgetGetEmbedResponse.class, - GsonVKNewsGetSettingsResponse.class, - GsonYandexMetrikaGetSettingsResponse.class, - GsonYandexMetrikaGetEmbedResponse.class - ); - } - -} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/ShopModelsRegistry.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/ShopModelsRegistry.java deleted file mode 100644 index c138949..0000000 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/ShopModelsRegistry.java +++ /dev/null @@ -1,59 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.AdditionalFieldModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.ShopModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.coupon.CouponModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.coupon.CouponsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.mass.sale.MassSaleModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.mass.sale.MassSalesListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.PaymentModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.PaymentsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.SentCommandModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.pending.PendingPaymentModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.product.ProductModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.product.ProductsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.purchase.*; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.server.ServerModel; -import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.server.ServersListModel; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class ShopModelsRegistry extends AbstractJsonModelsRegistry { - - private static final ShopModelsRegistry SINGLETON = new ShopModelsRegistry(); - - public ShopModelsRegistry() { - super(JsonModelsGroup.API_V3_SHOP_MODELS); - } - - public static @NotNull ShopModelsRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - AdditionalFieldModel.class, - CouponDiscountModel.class, - CouponModel.class, - CouponsListModel.class, - DiscountsModel.class, - FilledAdditionalFieldModel.class, - MassSaleDiscountModel.class, - MassSaleModel.class, - MassSalesListModel.class, - PaymentModel.class, - PaymentsListModel.class, - PendingPaymentModel.class, - ProductModel.class, - ProductsListModel.class, - PurchasedProductModel.class, - SentCommandModel.class, - ServerModel.class, - ServersListModel.class, - ShopModel.class - ); - } - -} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/ShopResponsesRegistry.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/ShopResponsesRegistry.java deleted file mode 100644 index 9c3ac98..0000000 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/gson/ShopResponsesRegistry.java +++ /dev/null @@ -1,38 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.gson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.response.gson.GsonErrorResponse; -import ru.easydonate.easydonate4j.api.v3.response.gson.shop.*; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class ShopResponsesRegistry extends AbstractJsonModelsRegistry { - - private static final ShopResponsesRegistry SINGLETON = new ShopResponsesRegistry(); - - public ShopResponsesRegistry() { - super(JsonModelsGroup.API_V3_SHOP_RESPONSES); - } - - public static @NotNull ShopResponsesRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - GsonErrorResponse.class, - GsonCreatePaymentResponse.class, - GsonGetCouponsListResponse.class, - GsonGetMassSalesListResponse.class, - GsonGetPaymentResponse.class, - GsonGetPaymentsListResponse.class, - GsonGetProductResponse.class, - GsonGetProductsListResponse.class, - GsonGetServerResponse.class, - GsonGetServersListResponse.class, - GsonGetShopResponse.class - ); - } - -} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/gson/ApiV3ModelsRegistry.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/gson/ApiV3ModelsRegistry.java new file mode 100644 index 0000000..ba65cc1 --- /dev/null +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/gson/ApiV3ModelsRegistry.java @@ -0,0 +1,126 @@ +package ru.easydonate.easydonate4j.json.serialization.implementation.registry.gson; + +import org.jetbrains.annotations.NotNull; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.discord.widget.DiscordWidgetPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.custom.messages.CustomMessagesPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.last.payments.LastPaymentsPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.surcharge.SurchargeDiscountModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.surcharge.SurchargeDiscountsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.easydonate.surcharge.SurchargePluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.vkontakte.community.widget.VKCommunityWidgetPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.vkontakte.messages.widget.VKMessagesWidgetPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.vkontakte.news.VKNewsPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.plugin.yandex.metrika.YandexMetrikaPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.AdditionalFieldModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.ShopModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.coupon.CouponModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.coupon.CouponsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.mass.sale.MassSaleModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.mass.sale.MassSalesListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.PaymentModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.PaymentsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.SentCommandModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.payment.pending.PendingPaymentModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.product.ProductModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.product.ProductsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.purchase.*; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.server.ServerModel; +import ru.easydonate.easydonate4j.api.v3.data.model.gson.shop.server.ServersListModel; +import ru.easydonate.easydonate4j.api.v3.response.gson.GsonErrorResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.discord.widget.GsonDiscordWidgetGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.discord.widget.GsonDiscordWidgetGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.custom.messages.GsonCustomMessagesGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.last.payments.GsonLastPaymentsGetPaymentsListResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.last.payments.GsonLastPaymentsGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.surcharge.GsonSurchargeGetDiscountResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.surcharge.GsonSurchargeGetDiscountsListResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.easydonate.surcharge.GsonSurchargeGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.community.widget.GsonVKCommunityWidgetGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.community.widget.GsonVKCommunityWidgetGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.messages.widget.GsonVKMessagesWidgetGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.messages.widget.GsonVKMessagesWidgetGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.vkontakte.news.GsonVKNewsGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.yandex.metrika.GsonYandexMetrikaGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.plugin.yandex.metrika.GsonYandexMetrikaGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.gson.shop.*; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; + +public final class ApiV3ModelsRegistry extends AbstractJsonModelsRegistry { + + private static final ApiV3ModelsRegistry SINGLETON = new ApiV3ModelsRegistry(); + + public ApiV3ModelsRegistry() { + super(JsonModelsGroup.API_V3_MODELS); + } + + public static @NotNull ApiV3ModelsRegistry getSingleton() { + return SINGLETON; + } + + @Override + public void register() { + registerImplementationAliases( + // --- shop models + AdditionalFieldModel.class, + CouponDiscountModel.class, + CouponModel.class, + CouponsListModel.class, + DiscountsModel.class, + FilledAdditionalFieldModel.class, + MassSaleDiscountModel.class, + MassSaleModel.class, + MassSalesListModel.class, + PaymentModel.class, + PaymentsListModel.class, + PendingPaymentModel.class, + ProductModel.class, + ProductsListModel.class, + PurchasedProductModel.class, + SentCommandModel.class, + ServerModel.class, + ServersListModel.class, + ShopModel.class, + // --- shop responses + GsonErrorResponse.class, + GsonCreatePaymentResponse.class, + GsonGetCouponsListResponse.class, + GsonGetMassSalesListResponse.class, + GsonGetPaymentResponse.class, + GsonGetPaymentsListResponse.class, + GsonGetProductResponse.class, + GsonGetProductsListResponse.class, + GsonGetServerResponse.class, + GsonGetServersListResponse.class, + GsonGetShopResponse.class, + // --- plugin models + SurchargePluginSettingsModel.class, + SurchargeDiscountModel.class, + SurchargeDiscountsListModel.class, + LastPaymentsPluginSettingsModel.class, + CustomMessagesPluginSettingsModel.class, + DiscordWidgetPluginSettingsModel.class, + VKCommunityWidgetPluginSettingsModel.class, + VKMessagesWidgetPluginSettingsModel.class, + VKNewsPluginSettingsModel.class, + YandexMetrikaPluginSettingsModel.class, + // --- plugin responses + GsonSurchargeGetSettingsResponse.class, + GsonSurchargeGetDiscountResponse.class, + GsonSurchargeGetDiscountsListResponse.class, + GsonLastPaymentsGetSettingsResponse.class, + GsonLastPaymentsGetPaymentsListResponse.class, + GsonCustomMessagesGetSettingsResponse.class, + GsonDiscordWidgetGetSettingsResponse.class, + GsonDiscordWidgetGetEmbedResponse.class, + GsonVKCommunityWidgetGetSettingsResponse.class, + GsonVKCommunityWidgetGetEmbedResponse.class, + GsonVKMessagesWidgetGetSettingsResponse.class, + GsonVKMessagesWidgetGetEmbedResponse.class, + GsonVKNewsGetSettingsResponse.class, + GsonYandexMetrikaGetSettingsResponse.class, + GsonYandexMetrikaGetEmbedResponse.class + ); + } + +} diff --git a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/callback/gson/CallbackApiModelsRegistry.java b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/gson/CallbackApiModelsRegistry.java similarity index 98% rename from json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/callback/gson/CallbackApiModelsRegistry.java rename to json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/gson/CallbackApiModelsRegistry.java index 04351d2..b7f24e9 100644 --- a/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/callback/gson/CallbackApiModelsRegistry.java +++ b/json-providers/gson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/gson/CallbackApiModelsRegistry.java @@ -1,4 +1,4 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.callback.gson; +package ru.easydonate.easydonate4j.json.serialization.implementation.registry.gson; import org.jetbrains.annotations.NotNull; import ru.easydonate.easydonate4j.callback.data.model.gson.mass.sale.MassSaleModel; diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/jackson/shop/purchase/DiscountsModel.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/jackson/shop/purchase/DiscountsModel.java index c41e16e..bf9fcba 100644 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/jackson/shop/purchase/DiscountsModel.java +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/api/v3/data/model/jackson/shop/purchase/DiscountsModel.java @@ -2,13 +2,21 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.AllArgsConstructor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import ru.easydonate.easydonate4j.api.v3.data.model.shop.purchase.CouponDiscount; import ru.easydonate.easydonate4j.api.v3.data.model.shop.purchase.Discounts; import ru.easydonate.easydonate4j.api.v3.data.model.shop.purchase.MassSaleDiscount; import ru.easydonate.easydonate4j.json.serialization.Implementing; import ru.easydonate.easydonate4j.util.Wrapper; +import java.io.IOException; import java.util.Objects; import java.util.Optional; @@ -20,6 +28,11 @@ public class DiscountsModel implements Discounts { @JsonProperty("coupon") private CouponDiscount usedCoupon; + @JsonIgnore + public static @NotNull DiscountsArrayDeserializer getDeserializer(@NotNull ObjectMapper unsafeMapperInstance) { + return new DiscountsArrayDeserializer(unsafeMapperInstance); + } + @JsonIgnore @Override public @NotNull Optional getActiveMassSale() { @@ -55,4 +68,22 @@ public int hashCode() { '}'; } + @AllArgsConstructor + private static final class DiscountsArrayDeserializer extends JsonDeserializer { + + private final ObjectMapper unsafeMapperInstance; + + @Override + public @Nullable DiscountsModel deserialize( + @NotNull JsonParser parser, + @NotNull DeserializationContext context + ) throws IOException { + if(parser.getCurrentToken() == JsonToken.START_ARRAY) + return null; + + return unsafeMapperInstance.readValue(parser, DiscountsModel.class); + } + + } + } diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/jackson/purchase/DiscountsModel.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/jackson/purchase/DiscountsModel.java index a9fab98..ecaf293 100644 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/jackson/purchase/DiscountsModel.java +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/callback/data/model/jackson/purchase/DiscountsModel.java @@ -2,13 +2,21 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.AllArgsConstructor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import ru.easydonate.easydonate4j.callback.data.model.purchase.CouponDiscount; import ru.easydonate.easydonate4j.callback.data.model.purchase.Discounts; import ru.easydonate.easydonate4j.callback.data.model.purchase.MassSaleDiscount; import ru.easydonate.easydonate4j.json.serialization.Implementing; import ru.easydonate.easydonate4j.util.Wrapper; +import java.io.IOException; import java.util.Objects; import java.util.Optional; @@ -20,6 +28,11 @@ public class DiscountsModel implements Discounts { @JsonProperty("coupon") private CouponDiscount usedCoupon; + @JsonIgnore + public static @NotNull DiscountsArrayDeserializer getDeserializer(@NotNull ObjectMapper unsafeMapperInstance) { + return new DiscountsArrayDeserializer(unsafeMapperInstance); + } + @JsonIgnore @Override public @NotNull Optional getActiveMassSale() { @@ -55,4 +68,22 @@ public int hashCode() { '}'; } + @AllArgsConstructor + private static final class DiscountsArrayDeserializer extends JsonDeserializer { + + private final ObjectMapper unsafeMapperInstance; + + @Override + public @Nullable DiscountsModel deserialize( + @NotNull JsonParser parser, + @NotNull DeserializationContext context + ) throws IOException { + if(parser.getCurrentToken() == JsonToken.START_ARRAY) + return null; + + return unsafeMapperInstance.readValue(parser, DiscountsModel.class); + } + + } + } diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/JacksonSerializationService.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/JacksonSerializationService.java index 82b094e..458be7d 100644 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/JacksonSerializationService.java +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/JacksonSerializationService.java @@ -6,13 +6,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import ru.easydonate.easydonate4j.exception.JsonSerializationException; -import ru.easydonate.easydonate4j.json.serialization.failsafe.JacksonFailsafeModule; +import ru.easydonate.easydonate4j.json.serialization.failsafe.jackson.ApiV3FailsafeModule; +import ru.easydonate.easydonate4j.json.serialization.failsafe.jackson.CallbackApiFailsafeModule; import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson.PluginModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson.PluginResponsesRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson.ShopModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson.ShopResponsesRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.callback.jackson.CallbackApiModelsRegistry; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.jackson.ApiV3ModelsRegistry; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.jackson.CallbackApiModelsRegistry; import ru.easydonate.easydonate4j.module.ModuleAlreadyRegisteredException; import ru.easydonate.easydonate4j.module.ModuleRegistrator; import ru.easydonate.easydonate4j.module.ModuleType; @@ -23,7 +21,6 @@ public final class JacksonSerializationService extends AbstractJsonSerialization public JacksonSerializationService() { this.objectMapper = createObjectMapper(); - this.objectMapper.registerModule(new JacksonFailsafeModule(createObjectMapper())); } public static void register() throws ModuleAlreadyRegisteredException { @@ -50,20 +47,13 @@ public static boolean isRegistered() { @Override public void registerImplementationAliasesGroup(@NotNull JsonModelsGroup jsonModelsGroup) { switch (jsonModelsGroup) { - case API_V3_SHOP_MODELS: - registerModelsGroup(jsonModelsGroup, ShopModelsRegistry.getSingleton()); - break; - case API_V3_SHOP_RESPONSES: - registerModelsGroup(jsonModelsGroup, ShopResponsesRegistry.getSingleton()); - break; - case API_V3_PLUGIN_MODELS: - registerModelsGroup(jsonModelsGroup, PluginModelsRegistry.getSingleton()); - break; - case API_V3_PLUGIN_RESPONSES: - registerModelsGroup(jsonModelsGroup, PluginResponsesRegistry.getSingleton()); + case API_V3_MODELS: + registerModelsGroup(jsonModelsGroup, ApiV3ModelsRegistry.getSingleton()); + new ApiV3FailsafeModule(createObjectMapper()).register(objectMapper); break; case CALLBACK_API_MODELS: registerModelsGroup(jsonModelsGroup, CallbackApiModelsRegistry.getSingleton()); + new CallbackApiFailsafeModule(createObjectMapper()).register(objectMapper); break; default: throw new IllegalArgumentException(String.format("An unexpected json models group received: %s!", jsonModelsGroup)); diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/deserializer/jackson/DiscountsArrayDeserializer.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/deserializer/jackson/DiscountsArrayDeserializer.java deleted file mode 100644 index bba790f..0000000 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/deserializer/jackson/DiscountsArrayDeserializer.java +++ /dev/null @@ -1,31 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.deserializer.jackson; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.AllArgsConstructor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.purchase.DiscountsModel; - -import java.io.IOException; - -@AllArgsConstructor -public final class DiscountsArrayDeserializer extends JsonDeserializer { - - private final ObjectMapper unsafeMapperInstance; - - @Override - public @Nullable DiscountsModel deserialize( - @NotNull JsonParser parser, - @NotNull DeserializationContext context - ) throws IOException { - if(parser.getCurrentToken() == JsonToken.START_ARRAY) - return null; - - return unsafeMapperInstance.readValue(parser, DiscountsModel.class); - } - -} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/JacksonFailsafeModule.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/JacksonFailsafeModule.java deleted file mode 100644 index cd69475..0000000 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/JacksonFailsafeModule.java +++ /dev/null @@ -1,18 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.failsafe; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.purchase.DiscountsModel; -import ru.easydonate.easydonate4j.json.serialization.deserializer.jackson.DiscountsArrayDeserializer; - -public final class JacksonFailsafeModule extends SimpleModule { - - public JacksonFailsafeModule(@NotNull ObjectMapper unsafeMapperInstance) { - super("EasyDonate4J-FailSafe"); - - // Bug [12.01.22]: some payment objects has an empty array instead of `null` for the `sales` field - super.addDeserializer(DiscountsModel.class, new DiscountsArrayDeserializer(unsafeMapperInstance)); - } - -} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/ApiV3FailsafeModule.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/ApiV3FailsafeModule.java new file mode 100644 index 0000000..c69e9df --- /dev/null +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/ApiV3FailsafeModule.java @@ -0,0 +1,16 @@ +package ru.easydonate.easydonate4j.json.serialization.failsafe.jackson; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.jetbrains.annotations.NotNull; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.purchase.DiscountsModel; + +public final class ApiV3FailsafeModule extends JacksonFailsafeModule { + + public ApiV3FailsafeModule(@NotNull ObjectMapper unsafeMapperInstance) { + super("API-v3", unsafeMapperInstance); + + // Bug [12.01.22]: some payment objects has an empty array instead of `null` for the `sales` field + super.addDeserializer(DiscountsModel.class, DiscountsModel.getDeserializer(unsafeMapperInstance)); + } + +} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/CallbackApiFailsafeModule.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/CallbackApiFailsafeModule.java new file mode 100644 index 0000000..10b5d77 --- /dev/null +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/CallbackApiFailsafeModule.java @@ -0,0 +1,16 @@ +package ru.easydonate.easydonate4j.json.serialization.failsafe.jackson; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.jetbrains.annotations.NotNull; +import ru.easydonate.easydonate4j.callback.data.model.jackson.purchase.DiscountsModel; + +public final class CallbackApiFailsafeModule extends JacksonFailsafeModule { + + public CallbackApiFailsafeModule(@NotNull ObjectMapper unsafeMapperInstance) { + super("Callback-API", unsafeMapperInstance); + + // Bug [12.01.22]: some payment objects has an empty array instead of `null` for the `sales` field + super.addDeserializer(DiscountsModel.class, DiscountsModel.getDeserializer(unsafeMapperInstance)); + } + +} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/JacksonFailsafeModule.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/JacksonFailsafeModule.java new file mode 100644 index 0000000..ea68148 --- /dev/null +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/failsafe/jackson/JacksonFailsafeModule.java @@ -0,0 +1,17 @@ +package ru.easydonate.easydonate4j.json.serialization.failsafe.jackson; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import org.jetbrains.annotations.NotNull; + +public abstract class JacksonFailsafeModule extends SimpleModule { + + protected JacksonFailsafeModule(@NotNull String moduleId, @NotNull ObjectMapper unsafeMapperInstance) { + super("EasyDonate4J-Failsafe-" + moduleId); + } + + public void register(@NotNull ObjectMapper objectMapper) { + objectMapper.registerModule(this); + } + +} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/PluginModelsRegistry.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/PluginModelsRegistry.java deleted file mode 100644 index 441970f..0000000 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/PluginModelsRegistry.java +++ /dev/null @@ -1,45 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.discord.widget.DiscordWidgetPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.custom.messages.CustomMessagesPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.last.payments.LastPaymentsPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.surcharge.SurchargeDiscountModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.surcharge.SurchargeDiscountsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.surcharge.SurchargePluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.vkontakte.community.widget.VKCommunityWidgetPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.vkontakte.messages.widget.VKMessagesWidgetPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.vkontakte.news.VKNewsPluginSettingsModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.yandex.metrika.YandexMetrikaPluginSettingsModel; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class PluginModelsRegistry extends AbstractJsonModelsRegistry { - - private static final PluginModelsRegistry SINGLETON = new PluginModelsRegistry(); - - public PluginModelsRegistry() { - super(JsonModelsGroup.API_V3_PLUGIN_MODELS); - } - - public static @NotNull PluginModelsRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - SurchargePluginSettingsModel.class, - SurchargeDiscountModel.class, - SurchargeDiscountsListModel.class, - LastPaymentsPluginSettingsModel.class, - CustomMessagesPluginSettingsModel.class, - DiscordWidgetPluginSettingsModel.class, - VKCommunityWidgetPluginSettingsModel.class, - VKMessagesWidgetPluginSettingsModel.class, - VKNewsPluginSettingsModel.class, - YandexMetrikaPluginSettingsModel.class - ); - } - -} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/PluginResponsesRegistry.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/PluginResponsesRegistry.java deleted file mode 100644 index f2a0330..0000000 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/PluginResponsesRegistry.java +++ /dev/null @@ -1,55 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.discord.widget.JacksonDiscordWidgetGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.discord.widget.JacksonDiscordWidgetGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.custom.messages.JacksonCustomMessagesGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.last.payments.JacksonLastPaymentsGetPaymentsListResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.last.payments.JacksonLastPaymentsGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.surcharge.JacksonSurchargeGetDiscountResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.surcharge.JacksonSurchargeGetDiscountsListResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.surcharge.JacksonSurchargeGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.community.widget.JacksonVKCommunityWidgetGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.community.widget.JacksonVKCommunityWidgetGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.messages.widget.JacksonVKMessagesWidgetGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.messages.widget.JacksonVKMessagesWidgetGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.news.JacksonVKNewsGetSettingsResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.yandex.metrika.JacksonYandexMetrikaGetEmbedResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.yandex.metrika.JacksonYandexMetrikaGetSettingsResponse; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class PluginResponsesRegistry extends AbstractJsonModelsRegistry { - - private static final PluginResponsesRegistry SINGLETON = new PluginResponsesRegistry(); - - public PluginResponsesRegistry() { - super(JsonModelsGroup.API_V3_PLUGIN_RESPONSES); - } - - public static @NotNull PluginResponsesRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - JacksonSurchargeGetSettingsResponse.class, - JacksonSurchargeGetDiscountResponse.class, - JacksonSurchargeGetDiscountsListResponse.class, - JacksonLastPaymentsGetSettingsResponse.class, - JacksonLastPaymentsGetPaymentsListResponse.class, - JacksonCustomMessagesGetSettingsResponse.class, - JacksonDiscordWidgetGetSettingsResponse.class, - JacksonDiscordWidgetGetEmbedResponse.class, - JacksonVKCommunityWidgetGetSettingsResponse.class, - JacksonVKCommunityWidgetGetEmbedResponse.class, - JacksonVKMessagesWidgetGetSettingsResponse.class, - JacksonVKMessagesWidgetGetEmbedResponse.class, - JacksonVKNewsGetSettingsResponse.class, - JacksonYandexMetrikaGetSettingsResponse.class, - JacksonYandexMetrikaGetEmbedResponse.class - ); - } - -} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/ShopModelsRegistry.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/ShopModelsRegistry.java deleted file mode 100644 index a9135b7..0000000 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/ShopModelsRegistry.java +++ /dev/null @@ -1,59 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.AdditionalFieldModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.ShopModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.coupon.CouponModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.coupon.CouponsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.mass.sale.MassSaleModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.mass.sale.MassSalesListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.PaymentModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.PaymentsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.SentCommandModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.pending.PendingPaymentModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.product.ProductModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.product.ProductsListModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.purchase.*; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.server.ServerModel; -import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.server.ServersListModel; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class ShopModelsRegistry extends AbstractJsonModelsRegistry { - - private static final ShopModelsRegistry SINGLETON = new ShopModelsRegistry(); - - public ShopModelsRegistry() { - super(JsonModelsGroup.API_V3_SHOP_MODELS); - } - - public static @NotNull ShopModelsRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - AdditionalFieldModel.class, - CouponDiscountModel.class, - CouponModel.class, - CouponsListModel.class, - DiscountsModel.class, - FilledAdditionalFieldModel.class, - MassSaleDiscountModel.class, - MassSaleModel.class, - MassSalesListModel.class, - PaymentModel.class, - PaymentsListModel.class, - PendingPaymentModel.class, - ProductModel.class, - ProductsListModel.class, - PurchasedProductModel.class, - SentCommandModel.class, - ServerModel.class, - ServersListModel.class, - ShopModel.class - ); - } - -} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/ShopResponsesRegistry.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/ShopResponsesRegistry.java deleted file mode 100644 index c30f790..0000000 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/api/v3/jackson/ShopResponsesRegistry.java +++ /dev/null @@ -1,38 +0,0 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.api.v3.jackson; - -import org.jetbrains.annotations.NotNull; -import ru.easydonate.easydonate4j.api.v3.response.jackson.JacksonErrorResponse; -import ru.easydonate.easydonate4j.api.v3.response.jackson.shop.*; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; -import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; - -public final class ShopResponsesRegistry extends AbstractJsonModelsRegistry { - - private static final ShopResponsesRegistry SINGLETON = new ShopResponsesRegistry(); - - public ShopResponsesRegistry() { - super(JsonModelsGroup.API_V3_SHOP_RESPONSES); - } - - public static @NotNull ShopResponsesRegistry getSingleton() { - return SINGLETON; - } - - @Override - public void register() { - registerImplementationAliases( - JacksonErrorResponse.class, - JacksonCreatePaymentResponse.class, - JacksonGetCouponsListResponse.class, - JacksonGetMassSalesListResponse.class, - JacksonGetPaymentResponse.class, - JacksonGetPaymentsListResponse.class, - JacksonGetProductResponse.class, - JacksonGetProductsListResponse.class, - JacksonGetServerResponse.class, - JacksonGetServersListResponse.class, - JacksonGetShopResponse.class - ); - } - -} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/jackson/ApiV3ModelsRegistry.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/jackson/ApiV3ModelsRegistry.java new file mode 100644 index 0000000..07db57d --- /dev/null +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/jackson/ApiV3ModelsRegistry.java @@ -0,0 +1,126 @@ +package ru.easydonate.easydonate4j.json.serialization.implementation.registry.jackson; + +import org.jetbrains.annotations.NotNull; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.discord.widget.DiscordWidgetPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.custom.messages.CustomMessagesPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.last.payments.LastPaymentsPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.surcharge.SurchargeDiscountModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.surcharge.SurchargeDiscountsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.easydonate.surcharge.SurchargePluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.vkontakte.community.widget.VKCommunityWidgetPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.vkontakte.messages.widget.VKMessagesWidgetPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.vkontakte.news.VKNewsPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.plugin.yandex.metrika.YandexMetrikaPluginSettingsModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.AdditionalFieldModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.ShopModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.coupon.CouponModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.coupon.CouponsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.mass.sale.MassSaleModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.mass.sale.MassSalesListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.PaymentModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.PaymentsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.SentCommandModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.payment.pending.PendingPaymentModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.product.ProductModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.product.ProductsListModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.purchase.*; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.server.ServerModel; +import ru.easydonate.easydonate4j.api.v3.data.model.jackson.shop.server.ServersListModel; +import ru.easydonate.easydonate4j.api.v3.response.jackson.JacksonErrorResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.discord.widget.JacksonDiscordWidgetGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.discord.widget.JacksonDiscordWidgetGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.custom.messages.JacksonCustomMessagesGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.last.payments.JacksonLastPaymentsGetPaymentsListResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.last.payments.JacksonLastPaymentsGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.surcharge.JacksonSurchargeGetDiscountResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.surcharge.JacksonSurchargeGetDiscountsListResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.easydonate.surcharge.JacksonSurchargeGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.community.widget.JacksonVKCommunityWidgetGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.community.widget.JacksonVKCommunityWidgetGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.messages.widget.JacksonVKMessagesWidgetGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.messages.widget.JacksonVKMessagesWidgetGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.vkontakte.news.JacksonVKNewsGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.yandex.metrika.JacksonYandexMetrikaGetEmbedResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.plugin.yandex.metrika.JacksonYandexMetrikaGetSettingsResponse; +import ru.easydonate.easydonate4j.api.v3.response.jackson.shop.*; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.AbstractJsonModelsRegistry; +import ru.easydonate.easydonate4j.json.serialization.implementation.registry.JsonModelsGroup; + +public final class ApiV3ModelsRegistry extends AbstractJsonModelsRegistry { + + private static final ApiV3ModelsRegistry SINGLETON = new ApiV3ModelsRegistry(); + + public ApiV3ModelsRegistry() { + super(JsonModelsGroup.API_V3_MODELS); + } + + public static @NotNull ApiV3ModelsRegistry getSingleton() { + return SINGLETON; + } + + @Override + public void register() { + registerImplementationAliases( + // --- shop models + AdditionalFieldModel.class, + CouponDiscountModel.class, + CouponModel.class, + CouponsListModel.class, + DiscountsModel.class, + FilledAdditionalFieldModel.class, + MassSaleDiscountModel.class, + MassSaleModel.class, + MassSalesListModel.class, + PaymentModel.class, + PaymentsListModel.class, + PendingPaymentModel.class, + ProductModel.class, + ProductsListModel.class, + PurchasedProductModel.class, + SentCommandModel.class, + ServerModel.class, + ServersListModel.class, + ShopModel.class, + // --- shop responses + JacksonErrorResponse.class, + JacksonCreatePaymentResponse.class, + JacksonGetCouponsListResponse.class, + JacksonGetMassSalesListResponse.class, + JacksonGetPaymentResponse.class, + JacksonGetPaymentsListResponse.class, + JacksonGetProductResponse.class, + JacksonGetProductsListResponse.class, + JacksonGetServerResponse.class, + JacksonGetServersListResponse.class, + JacksonGetShopResponse.class, + // --- plugin models + SurchargePluginSettingsModel.class, + SurchargeDiscountModel.class, + SurchargeDiscountsListModel.class, + LastPaymentsPluginSettingsModel.class, + CustomMessagesPluginSettingsModel.class, + DiscordWidgetPluginSettingsModel.class, + VKCommunityWidgetPluginSettingsModel.class, + VKMessagesWidgetPluginSettingsModel.class, + VKNewsPluginSettingsModel.class, + YandexMetrikaPluginSettingsModel.class, + // --- plugin responses + JacksonSurchargeGetSettingsResponse.class, + JacksonSurchargeGetDiscountResponse.class, + JacksonSurchargeGetDiscountsListResponse.class, + JacksonLastPaymentsGetSettingsResponse.class, + JacksonLastPaymentsGetPaymentsListResponse.class, + JacksonCustomMessagesGetSettingsResponse.class, + JacksonDiscordWidgetGetSettingsResponse.class, + JacksonDiscordWidgetGetEmbedResponse.class, + JacksonVKCommunityWidgetGetSettingsResponse.class, + JacksonVKCommunityWidgetGetEmbedResponse.class, + JacksonVKMessagesWidgetGetSettingsResponse.class, + JacksonVKMessagesWidgetGetEmbedResponse.class, + JacksonVKNewsGetSettingsResponse.class, + JacksonYandexMetrikaGetSettingsResponse.class, + JacksonYandexMetrikaGetEmbedResponse.class + ); + } + +} diff --git a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/callback/jackson/CallbackApiModelsRegistry.java b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/jackson/CallbackApiModelsRegistry.java similarity index 97% rename from json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/callback/jackson/CallbackApiModelsRegistry.java rename to json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/jackson/CallbackApiModelsRegistry.java index ab382b9..f48f005 100644 --- a/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/callback/jackson/CallbackApiModelsRegistry.java +++ b/json-providers/jackson-json-provider/src/main/java/ru/easydonate/easydonate4j/json/serialization/implementation/registry/jackson/CallbackApiModelsRegistry.java @@ -1,4 +1,4 @@ -package ru.easydonate.easydonate4j.json.serialization.implementation.registry.callback.jackson; +package ru.easydonate.easydonate4j.json.serialization.implementation.registry.jackson; import org.jetbrains.annotations.NotNull; import ru.easydonate.easydonate4j.callback.data.model.jackson.mass.sale.MassSaleModel; diff --git a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/ApacheHttpClientTesting.java b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/ApacheHttpClientTesting.java index b18347e..d168820 100644 --- a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/ApacheHttpClientTesting.java +++ b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/ApacheHttpClientTesting.java @@ -11,7 +11,7 @@ public final class ApacheHttpClientTesting extends SimpleHttpClientTestingModule @BeforeAll public static void init() { - ApacheHttpClientService.register(); + ApacheHttpClientService.registerIfNotRegisteredYet(); } } diff --git a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKLegacyHttpClientTesting.java b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKLegacyHttpClientTesting.java index 346ac73..384a42f 100644 --- a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKLegacyHttpClientTesting.java +++ b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKLegacyHttpClientTesting.java @@ -11,7 +11,7 @@ public final class JDKLegacyHttpClientTesting extends SimpleHttpClientTestingMod @BeforeAll public static void init() { - JDKLegacyHttpClientService.register(); + JDKLegacyHttpClientService.registerIfNotRegisteredYet(); } } diff --git a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKModernHttpClientTesting.java b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKModernHttpClientTesting.java index 636d294..d608b35 100644 --- a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKModernHttpClientTesting.java +++ b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/JDKModernHttpClientTesting.java @@ -11,7 +11,7 @@ public final class JDKModernHttpClientTesting extends SimpleHttpClientTestingMod @BeforeAll public static void init() { - JDKModernHttpClientService.register(); + JDKModernHttpClientService.registerIfNotRegisteredYet(); } } diff --git a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/OkHttp3HttpClientTesting.java b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/OkHttp3HttpClientTesting.java index 23e8976..20eeb0c 100644 --- a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/OkHttp3HttpClientTesting.java +++ b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/http/client/OkHttp3HttpClientTesting.java @@ -11,7 +11,7 @@ public final class OkHttp3HttpClientTesting extends SimpleHttpClientTestingModul @BeforeAll public static void init() { - OkHttpClientService.register(); + OkHttpClientService.registerIfNotRegisteredYet(); } } diff --git a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/GsonSerializationTesting.java b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/GsonSerializationTesting.java index a5eefcc..658705a 100644 --- a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/GsonSerializationTesting.java +++ b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/GsonSerializationTesting.java @@ -11,7 +11,7 @@ public final class GsonSerializationTesting extends SimpleJsonSerializationTesti @BeforeAll public static void init() { - GsonSerializationService.register(); + GsonSerializationService.registerIfNotRegisteredYet(); } } diff --git a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JacksonSerializationTesting.java b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JacksonSerializationTesting.java index c6aa32a..e9973ec 100644 --- a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JacksonSerializationTesting.java +++ b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JacksonSerializationTesting.java @@ -11,7 +11,7 @@ public final class JacksonSerializationTesting extends SimpleJsonSerializationTe @BeforeAll public static void init() { - JacksonSerializationService.register(); + JacksonSerializationService.registerIfNotRegisteredYet(); } } diff --git a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JsonSerializationTestingModule.java b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JsonSerializationTestingModule.java index 78516ac..e98281e 100644 --- a/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JsonSerializationTestingModule.java +++ b/testing/api-v3-testing/src/test/java/ru/easydonate/easydonate4j/testing/api/v3/json/serialization/JsonSerializationTestingModule.java @@ -28,11 +28,7 @@ public abstract class JsonSerializationTestingModule extends TestingModule { @DisplayName("Serialization service initialization") public void printRegisteredSerializationService() { JsonSerializationService jsonSerializationService = ModuleRegistrator.get().getJsonSerializationService(); - - jsonSerializationService.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_SHOP_MODELS); - jsonSerializationService.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_SHOP_RESPONSES); - jsonSerializationService.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_PLUGIN_MODELS); - jsonSerializationService.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_PLUGIN_RESPONSES); + jsonSerializationService.registerImplementationAliasesGroup(JsonModelsGroup.API_V3_MODELS); logger.info("Registered serialization service: " + jsonSerializationService.getType()); } diff --git a/testing/callback-api-testing/src/test/java/ru/easydonate/easydonate4j/testing/callback/api/callback/CallbackApiTesting.java b/testing/callback-api-testing/src/test/java/ru/easydonate/easydonate4j/testing/callback/api/callback/CallbackApiTesting.java index ef2bc92..fb54a06 100644 --- a/testing/callback-api-testing/src/test/java/ru/easydonate/easydonate4j/testing/callback/api/callback/CallbackApiTesting.java +++ b/testing/callback-api-testing/src/test/java/ru/easydonate/easydonate4j/testing/callback/api/callback/CallbackApiTesting.java @@ -39,8 +39,7 @@ public CallbackApiTesting() { @BeforeAll public static void preInit() { - if(!JacksonSerializationService.isRegistered()) - JacksonSerializationService.register(); + JacksonSerializationService.registerIfNotRegisteredYet(); } @Test