serialize and deserialize enum with Gson
This works fine as well, don't know from which version of GSON though:
public enum OrderLineTimeRegistrationStatus {
None(0), Started(1), Paused(2);
private int value;
private OrderLineTimeRegistrationStatus(int value)
{
this.value=value;
}
public int getValue()
{
return(value);
}
}
You can try this.
import com.google.gson.annotations.SerializedName;
public enum Color {
@SerializedName("0")
RED (0),
@SerializedName("1")
BLUE (1),
@SerializedName("2")
YELLOW (2);
private final int value;
public int getValue() {
return value;
}
private Color(int value) {
this.value = value;
}
}
According to Gson API documentation, Gson provides default serialization/deserialization of Enum
, so basically it should be serialized and deserialized using the standard toJson
and fromJson
methods, as with any other type.