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

me.xhsun.guildwars2wrapper.model.v2.util.skillFact.BooleanAdapter Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package me.xhsun.guildwars2wrapper.model.v2.util.skillFact;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;

/**
 * Use for {@link SkillFact} for when type is {@link me.xhsun.guildwars2wrapper.model.v2.util.skillFact.SkillFact.Type#Unblockable}
 * the value is boolean instead of int
 *
 * @author xhsun
 * @since 2017-06-15
 */
public class BooleanAdapter implements JsonDeserializer {

	@Override
	public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
		try {
			return json.getAsInt();
		} catch (NumberFormatException e) {
			return (json.getAsBoolean()) ? 1 : 0;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy