1

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.

Andrew
  • 11
  • 4
  • The code you posted looks OK to me. The problem could also be related to the "tables" part of the json, in which the string "0" also appears, under flows. Could you post the relevant code? – johnnyaug Apr 16 '18 at 13:13
  • Possible duplicate of [How do I deserialize a JSON array that contains only values?](https://stackoverflow.com/questions/29001023/how-do-i-deserialize-a-json-array-that-contains-only-values) – krishank Tripathi Apr 16 '18 at 13:31

0 Answers0