I have a JSON array with a lot of entries and want to deserialize each check into a single object with gson. My problem is to find the proper object structure for it.
Annotation needs to be added to make GSON
eg: Add @SerializedName("client") before declaring the string client
@SerializedName("client")
public String client;
Instead of writing code repeatedly, you can do these in one go. check this - http://www.jsonschema2pojo.org/
You need to set the annotation like this to use GSON
public class Client {
@SerializedName("client")
public String client;
@SerializedName("check")
public Check check;
}
When we check your json from http://jsonviewer.stack.hu/ we see that "subdue" is not a String Array. It's an object.
So you need a class like:
public class Subdue {
public String at;
public String begin;
public String end;
}
and modify your Check Class like:
public class Check {
public Boolean handle;
public Boolean standaloone;
public int interval;
public int refresh;
public String[] dependencies;
public String commmand;
public int occurrences;
public String[] subscribers;
public Boolean aggregate;
public Subdue subdue;
public String name;
public int issued;
public int executed;
public float duration;
public String output;
public int status;
}
I couldn't see any other problems. I hope this'll help you. Good Luck.