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

com.pengrad.telegrambot.utility.gson.BackgroundFillAdapter Maven / Gradle / Ivy

There is a newer version: 7.11.0
Show newest version
package com.pengrad.telegrambot.utility.gson;

import com.google.gson.*;
import com.pengrad.telegrambot.model.chatbackground.BackgroundFill;
import com.pengrad.telegrambot.model.chatbackground.BackgroundFillFreeformGradient;
import com.pengrad.telegrambot.model.chatbackground.BackgroundFillGradient;
import com.pengrad.telegrambot.model.chatbackground.BackgroundFillSolid;

import java.lang.reflect.Type;

public class BackgroundFillAdapter implements JsonDeserializer {

    @Override
    public BackgroundFill deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException {
        JsonObject object = element.getAsJsonObject();
        String discriminator = object.getAsJsonPrimitive("type").getAsString();

        if (BackgroundFillSolid.TYPE.equals(discriminator)) {
            return context.deserialize(object, BackgroundFillSolid.class);
        } else if (BackgroundFillGradient.TYPE.equals(discriminator)) {
            return context.deserialize(object, BackgroundFillGradient.class);
        } else if (BackgroundFillFreeformGradient.TYPE.equals(discriminator)) {
            return context.deserialize(object, BackgroundFillFreeformGradient.class);
        }

        return context.deserialize(object, BackgroundFill.class);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy