Class XMLEnumTypeAdapter<T>

  • Type Parameters:
    T - The enum type.

    public class XMLEnumTypeAdapter<T>
    extends com.google.gson.TypeAdapter<T>
    Serializes and deserializes enums that use annotations for GSON.
    • Constructor Detail

      • XMLEnumTypeAdapter

        public XMLEnumTypeAdapter​(Class clazz)
        Instantiates a new XMLEnumTypeAdapter.
        Parameters:
        clazz - the enum class to be handled.
    • Method Detail

      • write

        public void write​(com.google.gson.stream.JsonWriter out,
                          T value)
                   throws IOException
        Writes the enum value to JSON, using the SerializedName if present.
        Specified by:
        write in class com.google.gson.TypeAdapter<T>
        Parameters:
        out - the GSON JsonWriter to write to.
        value - the enum constant to write to JSON.
        Throws:
        IOException
      • read

        public T read​(com.google.gson.stream.JsonReader in)
               throws IOException
        Reads a string from JSON and converts it to an enum constant. It first attempts to use a static fromValue method on the enum, then falls back to Enum.valueOf(Class, String). Returns null for unknown values.
        Specified by:
        read in class com.google.gson.TypeAdapter<T>
        Parameters:
        in - the GSON JsonReader to read from.
        Returns:
        The deserialized enum constant, or null if the value is unknown.
        Throws:
        IOException - if an I/O error occurs.