GSON Case-Insensitive Enum Deserialization

A simpler way I found (just now) to do this is to use the @SerializedName annotation. I found it in the EnumTest.java here (the Gender class around ln 195):

https://code.google.com/p/google-gson/source/browse/trunk/gson/src/test/java/com/google/gson/functional/EnumTest.java?r=1230

This assumes that all of your Types will come in as lowercase as opposed to being “case insensitive”

public enum Type {
    @SerializedName("live")
    LIVE,

    @SerializedName("upcoming")
    UPCOMING,

    @SerializedName("replay")
    REPLAY;
}

This was the simplest and most generic way I found to do this. Hope it helps you.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)