I am trying to parse a JSON object using GSON.
My JSON is :
{ "truncate": [
{
"lower": 20,
"upper": 40,
"delimiter": " ",
"scope": ["$title"]
},
{
"lower": 30,
"upper": 65,
"delimiter": " "
}
] }
I have defined my 2 classes like:
public class TruncateObj {
private List<TruncateObjectChild> objChild;
// getter and setter
}
and
public class TruncateObjectChild {
private int lower;
private int upper;
private String delimiter;
private List<String> scope;
// getters and setters
}
My Parsing statement is
Gson gson = new Gson();
TruncateObj truncation = gson.fromJson(template, TruncateObj.class);
For some reason this is not working. Gson creates a TruncatObj
child, but the List<TruncateObjectChild>
within the TruncateObj is null.
What is wrong in what I am doing?