All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.unzer.payment.communication.JsonWebhookEnumConverter Maven / Gradle / Ivy

package com.unzer.payment.communication;

import com.google.gson.*;
import com.unzer.payment.webhook.WebhookEventEnum;

import java.lang.reflect.Type;

public class JsonWebhookEnumConverter
        implements JsonDeserializer, JsonSerializer {

    @Override
    public JsonElement serialize(WebhookEventEnum src, Type typeOfSrc,
                                 JsonSerializationContext context) {
        return new JsonPrimitive(src.getEventName());
    }

    @Override
    public WebhookEventEnum deserialize(JsonElement json, Type typeOfT,
                                        JsonDeserializationContext context) {
        if (json == null || json.isJsonNull() || !json.isJsonPrimitive()) {
            return null;
        }

        String jsonValue = json.getAsString();
        return WebhookEventEnum.fromEventName(jsonValue);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy