001package net.bramp.ffmpeg.adapter; 002 003import com.google.gson.*; 004import java.lang.reflect.Type; 005 006public class BooleanTypeAdapter implements JsonDeserializer<Boolean> { 007 @Override 008 public Boolean deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) 009 throws JsonParseException { 010 if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isBoolean()) { 011 return json.getAsBoolean(); 012 } 013 014 if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) { 015 String jsonValue = json.getAsString(); 016 if (jsonValue.equalsIgnoreCase("true")) { 017 return true; 018 } else if (jsonValue.equalsIgnoreCase("false")) { 019 return false; 020 } else { 021 return null; 022 } 023 } 024 025 return json.getAsInt() != 0; 026 } 027}