I am trying to serialize a Restaurant class using Gson in order to put it in an SQLite table. The Restaurant class has, among others, a variable for storing a list of Statuses:
public class Restaurant extends RestaurantObservable implements Serializable {
private final List<Status> statuses = new ArrayList<Status>();
...
A status is an interface, and is defined as:
public interface Status {
public boolean hasDuration();
public long getMinuteDuration();
default long getMilliDuration() {
return getMinuteDuration() * 60000;
}
public String getName();
}
The most commonly used Status is a DefaultStatus. I have tried to use @SerializedName annotations for the serialization, thinking it would make it work. Here is the beginning part of the definition of the class:
public enum DefaultStatus implements Status {
@SerializedName("0")
UNOCCUPIED(0),
@SerializedName("5")
WELCOMED(5),
@SerializedName("3")
DRINK_ORDER(3),
...
I have also defined a custom InterfaceAdapter, because it would not have worked otherwise. However, when I try to deserialize my Restaurant object from the database I get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pewletthackard.waiterfocusapp/com.pewletthackard.waiterfocusapp.core.MainActivity}: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Not a JSON Object: "0"
Does anybody know what can I do about this? I have been trying to fix this issue for sometime now.
This is my json: https://justpaste.it/1jose.