Class IntegerMappedEnumSerializer<T extends Enum<T>>

java.lang.Object
io.datarouter.gson.serializer.IntegerMappedEnumSerializer<T>
All Implemented Interfaces:
com.google.gson.JsonDeserializer<T>, com.google.gson.JsonSerializer<T>

public class IntegerMappedEnumSerializer<T extends Enum<T>> extends Object implements com.google.gson.JsonSerializer<T>, com.google.gson.JsonDeserializer<T>
  • Method Details

    • required

      public static final <T extends Enum<T>> IntegerMappedEnumSerializer<T> required(io.datarouter.enums.MappedEnum<T,Integer> mappedEnum)
      When deserializing, throw an exception if the value is not found.
    • optional

      public static final <T extends Enum<T>> IntegerMappedEnumSerializer<T> optional(io.datarouter.enums.MappedEnum<T,Integer> mappedEnum, T replacement)
      When deserializing, return the replacement if the value is not found.
    • optionalWithLogging

      public static final <T extends Enum<T>> IntegerMappedEnumSerializer<T> optionalWithLogging(io.datarouter.enums.MappedEnum<T,Integer> mappedEnum, T replacement)
      When deserializing, return the replacement if the value is not found. Log the replacement.
    • serialize

      public com.google.gson.JsonElement serialize(T enumValue, Type typeOfSrc, com.google.gson.JsonSerializationContext context)
      Specified by:
      serialize in interface com.google.gson.JsonSerializer<T extends Enum<T>>
    • deserialize

      public T deserialize(com.google.gson.JsonElement json, Type typeOfT, com.google.gson.JsonDeserializationContext context) throws com.google.gson.JsonParseException
      Specified by:
      deserialize in interface com.google.gson.JsonDeserializer<T extends Enum<T>>
      Throws:
      com.google.gson.JsonParseException