I am having trouble with this json.
{"directory": {
"employees": {"employee": [
{
"field": [
{
"content": "Charlotte Abbott",
"id": "displayName"
},
{
"content": "Charlotte",
"id": "firstName"
},
I am casting it into a class that looks like this
@SerializedName("directory")
public Directory directory;
public class Directory
{
@SerializedName("employees")
public Employees employees;
}
public class Employees
{
@SerializedName("employee")
public List<Employee> employee;
}
public class Employee
{
@SerializedName("field")
public List<Fields> fields;
@SerializedName("id")
public String employeeId;
}
public class Fields
{
@SerializedName("content")
public String content;
@SerializedName("id")
public String label;
}
And it is not reaching all the variables to insert the data when it serializes. Instead I am getting all nulls. I am however getting the right amount (number) of Directory objects so I know it is reaching that far. Anyone have some insight on what I am doing wrong here? The json is the way it is, I didn’t design it, but it is how it is used.
Quite a weird data structure you have to work with, but here is it.
You need a
Wrapperclass to wrap aroundDirectory.Directoryclass.Employeesclass:Employeeclass:Fieldclass:See a JSON to Java Object using GSON example here: http://java.sg/parsing-a-json-string-into-an-object-with-gson-easily/