Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:45:20+00:00 2026-06-13T21:45:20+00:00

I am having trouble with this json. {directory: { employees: {employee: [ { field:

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:45:22+00:00Added an answer on June 13, 2026 at 9:45 pm

    Quite a weird data structure you have to work with, but here is it.

    public class App {
        public static void main(String[] args) {
            Gson gson = new Gson();
            String jsonString = "{\"directory\": {\"employees\": {\"employee\": [{\"field\": [{\"content\": \"Charlotte Abbott\",\"id\": \"displayName\"},{\"content\": \"Charlotte\",\"id\": \"firstName\"}]}]}}}";
    
            Wrapper obj = (Wrapper) gson.fromJson(jsonString, Wrapper.class);
    
            System.out.println(obj.getDirectory().getEmployees().getEmployeeList()
                    .get(0).getFieldList().get(0).getContent());
        }
    }
    

    You need a Wrapper class to wrap around Directory.

    public class Wrapper {
        private Directory directory;
    
        public Directory getDirectory() {
            return directory;
        }
    
        public void setDirectory(Directory directory) {
            this.directory = directory;
        }
    }
    

    Directory class.

    public class Directory {
        @SerializedName("employees")
        private Employees employees;
    
        public Employees getEmployees() {
            return employees;
        }
    
        public void setEmployees(Employees employees) {
            this.employees = employees;
        }
    }
    

    Employees class:

    public class Employees {
        @SerializedName("employee")
        private List<Employee> employeeList;
    
        public List<Employee> getEmployeeList() {
            return employeeList;
        }
    
        public void setEmployeeList(List<Employee> employeeList) {
            this.employeeList = employeeList;
        }
    }
    

    Employee class:

    public class Employee {
        @SerializedName("field")
        private List<Field> fieldList;
    
        public List<Field> getFieldList() {
            return fieldList;
        }
    
        public void setFieldList(List<Field> fieldList) {
            this.fieldList = fieldList;
        }
    }
    

    Field class:

    public class Field {
        @SerializedName("content")
        private String content;
        @SerializedName("id")
        private String id;
    
        public String getContent() {
            return content;
        }
    
        public void setContent(String content) {
            this.content = content;
        }
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    }
    

    See a JSON to Java Object using GSON example here: http://java.sg/parsing-a-json-string-into-an-object-with-gson-easily/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting this bit of JSON into a POJO. I'm using Jackson
Hi Im having trouble getting the Javascript serialiser to convert this Json string to
i have been having this trouble when trying to obtain json data. lets say
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
Continuing from this question . I'm having trouble deserializing the following json array (Sorry
I'm having trouble parsing Json string to Objects in C#. I'm using this: JavaScriptSerilizer
I'm learning spring for android with androidannotations and I'm having trouble casting JSON data
I am having trouble on formatting my json. Basically I have this script structure,
I'm having trouble converting objects into JSONObject (org.json.JSONObject) in java. I have an object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.