Package com.adyen.terminal.serialization
Class XMLEnumTypeAdapter<T>
- java.lang.Object
-
- com.google.gson.TypeAdapter<T>
-
- com.adyen.terminal.serialization.XMLEnumTypeAdapter<T>
-
- Type Parameters:
T- The enum type.
public class XMLEnumTypeAdapter<T> extends com.google.gson.TypeAdapter<T>Serializes and deserializes enums that useXmlEnumValueannotations for GSON.
-
-
Constructor Summary
Constructors Constructor Description XMLEnumTypeAdapter(Class clazz)Instantiates a newXMLEnumTypeAdapter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tread(com.google.gson.stream.JsonReader in)Reads a string from JSON and converts it to an enum constant.voidwrite(com.google.gson.stream.JsonWriter out, T value)Writes the enum value to JSON, using theXmlEnumValueif present.
-
-
-
Constructor Detail
-
XMLEnumTypeAdapter
public XMLEnumTypeAdapter(Class clazz)
Instantiates a newXMLEnumTypeAdapter.- Parameters:
clazz- the enum class to be handled.
-
-
Method Detail
-
write
public void write(com.google.gson.stream.JsonWriter out, T value) throws IOExceptionWrites the enum value to JSON, using theXmlEnumValueif present.- Specified by:
writein classcom.google.gson.TypeAdapter<T>- Parameters:
out- the GSONJsonWriterto 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 staticfromValuemethod on the enum, then falls back toEnum.valueOf(Class, String). Returnsnullfor unknown values.- Specified by:
readin classcom.google.gson.TypeAdapter<T>- Parameters:
in- the GSONJsonReaderto read from.- Returns:
- The deserialized enum constant, or
nullif the value is unknown. - Throws:
IOException- if an I/O error occurs.
-
-