com.pengrad.telegrambot.utility.gson.BackgroundFillAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-telegram-bot-api Show documentation
Show all versions of java-telegram-bot-api Show documentation
Java API for Telegram Bot API
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