|
| 1 | +/* |
| 2 | + * ###### |
| 3 | + * ###### |
| 4 | + * ############ ####( ###### #####. ###### ############ ############ |
| 5 | + * ############# #####( ###### #####. ###### ############# ############# |
| 6 | + * ###### #####( ###### #####. ###### ##### ###### ##### ###### |
| 7 | + * ###### ###### #####( ###### #####. ###### ##### ##### ##### ###### |
| 8 | + * ###### ###### #####( ###### #####. ###### ##### ##### ###### |
| 9 | + * ############# ############# ############# ############# ##### ###### |
| 10 | + * ############ ############ ############# ############ ##### ###### |
| 11 | + * ###### |
| 12 | + * ############# |
| 13 | + * ############ |
| 14 | + * |
| 15 | + * Adyen Java API Library |
| 16 | + * |
| 17 | + * Copyright (c) 2017 Adyen B.V. |
| 18 | + * This file is open source and available under the MIT license. |
| 19 | + * See the LICENSE file for more info. |
| 20 | + */ |
| 21 | + |
| 22 | +package com.adyen.deserializer; |
| 23 | + |
| 24 | +import java.lang.reflect.Type; |
| 25 | +import com.adyen.model.marketpay.notification.AccountCreatedNotification; |
| 26 | +import com.adyen.model.marketpay.notification.AccountHolderCreatedNotification; |
| 27 | +import com.adyen.model.marketpay.notification.AccountHolderLimitReachedNotification; |
| 28 | +import com.adyen.model.marketpay.notification.AccountHolderPayoutNotification; |
| 29 | +import com.adyen.model.marketpay.notification.AccountHolderStatusChangeNotification; |
| 30 | +import com.adyen.model.marketpay.notification.AccountHolderUpdatedNotification; |
| 31 | +import com.adyen.model.marketpay.notification.AccountHolderVerificationNotification; |
| 32 | +import com.adyen.model.marketpay.notification.BeneficiarySetupNotification; |
| 33 | +import com.adyen.model.marketpay.notification.CompensateNegativeBalanceNotification; |
| 34 | +import com.adyen.model.marketpay.notification.GenericNotification; |
| 35 | +import com.adyen.model.marketpay.notification.PaymentFailureNotification; |
| 36 | +import com.adyen.model.marketpay.notification.ReportAvailableNotification; |
| 37 | +import com.adyen.model.marketpay.notification.ScheduledRefundsNotification; |
| 38 | +import com.adyen.model.marketpay.notification.TransferFundsNotification; |
| 39 | +import com.google.gson.JsonDeserializationContext; |
| 40 | +import com.google.gson.JsonDeserializer; |
| 41 | +import com.google.gson.JsonElement; |
| 42 | +import com.google.gson.JsonObject; |
| 43 | +import com.google.gson.JsonParseException; |
| 44 | + |
| 45 | +public class MarketPayNotificationMessageDeserializer implements JsonDeserializer<GenericNotification> { |
| 46 | + @Override |
| 47 | + public GenericNotification deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { |
| 48 | + JsonObject jsonObject = jsonElement.getAsJsonObject(); |
| 49 | + |
| 50 | + JsonElement jsonType = jsonObject.get("eventType"); |
| 51 | + String eventType = jsonType.getAsString(); |
| 52 | + |
| 53 | + if (GenericNotification.EventTypeEnum.ACCOUNT_CREATED.toString().equalsIgnoreCase(eventType)) { |
| 54 | + return jsonDeserializationContext.deserialize(jsonElement, AccountCreatedNotification.class); |
| 55 | + } |
| 56 | + if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_CREATED.toString().equalsIgnoreCase(eventType)) { |
| 57 | + return jsonDeserializationContext.deserialize(jsonElement, AccountHolderCreatedNotification.class); |
| 58 | + } |
| 59 | + if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_LIMIT_REACHED.toString().equalsIgnoreCase(eventType)) { |
| 60 | + return jsonDeserializationContext.deserialize(jsonElement, AccountHolderLimitReachedNotification.class); |
| 61 | + } |
| 62 | + if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_VERIFICATION.toString().equalsIgnoreCase(eventType)) { |
| 63 | + return jsonDeserializationContext.deserialize(jsonElement, AccountHolderVerificationNotification.class); |
| 64 | + } |
| 65 | + if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_STATUS_CHANGE.toString().equalsIgnoreCase(eventType)) { |
| 66 | + return jsonDeserializationContext.deserialize(jsonElement, AccountHolderStatusChangeNotification.class); |
| 67 | + } |
| 68 | + if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_PAYOUT.toString().equalsIgnoreCase(eventType)) { |
| 69 | + return jsonDeserializationContext.deserialize(jsonElement, AccountHolderPayoutNotification.class); |
| 70 | + } |
| 71 | + if (GenericNotification.EventTypeEnum.ACCOUNT_HOLDER_UPDATED.toString().equalsIgnoreCase(eventType)) { |
| 72 | + return jsonDeserializationContext.deserialize(jsonElement, AccountHolderUpdatedNotification.class); |
| 73 | + } |
| 74 | + if (GenericNotification.EventTypeEnum.BENEFICIARY_SETUP.toString().equalsIgnoreCase(eventType)) { |
| 75 | + return jsonDeserializationContext.deserialize(jsonElement, BeneficiarySetupNotification.class); |
| 76 | + } |
| 77 | + if (GenericNotification.EventTypeEnum.SCHEDULED_REFUNDS.toString().equalsIgnoreCase(eventType)) { |
| 78 | + return jsonDeserializationContext.deserialize(jsonElement, ScheduledRefundsNotification.class); |
| 79 | + } |
| 80 | + if (GenericNotification.EventTypeEnum.COMPENSATE_NEGATIVE_BALANCE.toString().equalsIgnoreCase(eventType)) { |
| 81 | + return jsonDeserializationContext.deserialize(jsonElement, CompensateNegativeBalanceNotification.class); |
| 82 | + } |
| 83 | + if (GenericNotification.EventTypeEnum.PAYMENT_FAILURE.toString().equalsIgnoreCase(eventType)) { |
| 84 | + return jsonDeserializationContext.deserialize(jsonElement, PaymentFailureNotification.class); |
| 85 | + } |
| 86 | + if (GenericNotification.EventTypeEnum.REPORT_AVAILABLE.toString().equalsIgnoreCase(eventType)) { |
| 87 | + return jsonDeserializationContext.deserialize(jsonElement, ReportAvailableNotification.class); |
| 88 | + } |
| 89 | + if (GenericNotification.EventTypeEnum.TRANSFER_FUNDS.toString().equalsIgnoreCase(eventType)) { |
| 90 | + return jsonDeserializationContext.deserialize(jsonElement, TransferFundsNotification.class); |
| 91 | + } |
| 92 | + |
| 93 | + return jsonDeserializationContext.deserialize(jsonElement, GenericNotification.class); |
| 94 | + } |
| 95 | +} |
0 commit comments