Class SafeEnumAdapter<E extends java.lang.Enum<E>>

java.lang.Object
com.google.gson.TypeAdapter<E>
ai.nextbillion.maps.internal.SafeEnumAdapter<E>
Type Parameters:
E - the enum type to map values to.

public class SafeEnumAdapter<E extends java.lang.Enum<E>>
extends com.google.gson.TypeAdapter<E>
A TypeAdapter that maps case-insensitive values to an enum type. If the value is not found, an UNKNOWN value is returned, and logged. This allows the server to return values this client doesn't yet know about.
  • Constructor Summary

    Constructors 
    Constructor Description
    SafeEnumAdapter​(E unknownValue)  
  • Method Summary

    Modifier and Type Method Description
    E read​(com.google.gson.stream.JsonReader reader)  
    void write​(com.google.gson.stream.JsonWriter out, E value)  

    Methods inherited from class com.google.gson.TypeAdapter

    fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTree

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SafeEnumAdapter

      public SafeEnumAdapter​(E unknownValue)
      Parameters:
      unknownValue - the value to return if the value cannot be found.
  • Method Details

    • write

      public void write​(com.google.gson.stream.JsonWriter out, E value) throws java.io.IOException
      Specified by:
      write in class com.google.gson.TypeAdapter<E extends java.lang.Enum<E>>
      Throws:
      java.io.IOException
    • read

      public E read​(com.google.gson.stream.JsonReader reader) throws java.io.IOException
      Specified by:
      read in class com.google.gson.TypeAdapter<E extends java.lang.Enum<E>>
      Throws:
      java.io.IOException