Class EnumSerializer<E>

  • Type Parameters:
    E - the enumeration type the serializer should work with
    All Implemented Interfaces:
    com.google.gson.JsonDeserializer<E>, com.google.gson.JsonSerializer<E>

    public class EnumSerializer<E>
    extends Object
    implements com.google.gson.JsonSerializer<E>, com.google.gson.JsonDeserializer<E>
    Custom JSON serializer for enumerated types within IoT service models
    • Constructor Detail

      • EnumSerializer

        public EnumSerializer()
    • Method Detail

      • serialize

        public com.google.gson.JsonElement serialize​(E enumValue,
                                                     Type typeOfEnum,
                                                     com.google.gson.JsonSerializationContext context)
        Serializes the given enum to a JsonElement
        Specified by:
        serialize in interface com.google.gson.JsonSerializer<E>
        Parameters:
        enumValue - The enum to convert
        typeOfEnum - The enum to convert type
        context - The JsonSerializationContext to use
        Returns:
        The enum as a JsonElement
      • deserialize

        public E deserialize​(com.google.gson.JsonElement json,
                             Type typeOfEnum,
                             com.google.gson.JsonDeserializationContext context)
                      throws com.google.gson.JsonParseException
        Deserializes the JsonElement to an enum
        Specified by:
        deserialize in interface com.google.gson.JsonDeserializer<E>
        Parameters:
        json - The json to convert
        typeOfEnum - The type of enum to convert to
        context - The JsonDeserializationContext to use
        Returns:
        The enum from the JsonElement data
        Throws:
        com.google.gson.JsonParseException