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 7573961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:18:51+00:00 2026-05-30T16:18:51+00:00

This might be a bit long so please bear with me.. I’m working on

  • 0

This might be a bit long so please bear with me..

I’m working on a project in Android. I have a JSON string that i need to deserialize into objects representing the JSON structure, the JSON string is something like below:

{"parents":[
    {"parent":{
            "id":1,
            "name":"Sam",
            "childs":[
                {
                    "child":{
                        "id":1,
                        "name":"Alice",
                        "books":[
                            {
                                "book":{
                                    "id":1,
                                    "name":"Alice in Wonderland"
                                }
                            }
                        ]
                    }
                }
            ]
        } 

    }    
]}

Note that for arrays there are repeating values (i.e. many parent and many child) i just put one line here to make it short.

With this i created classes to accomodate the structure:

public class Containers{
    private List<Parent> parents;
    //setter and getter..
}

public static class Parent extends CommonItem {
    private List<Child> childs;
    //setter and getter..
}

public static class Child extends CommonItem {
    private List<Book> books;
    //setter and getter..
}

public class CommonItem{
    private int id;
    private String name;
    //setter and getter
}

Note that i’d created a common class to accommodate the repeating attributes.
Below is how i parse them using GSON:

Gson gson = new Gson();
Containers parents = gson.fromJson(jsonString, Containers.class);

After parsing (there’re no error) i try to retrieve the objects. The number of object count in the parents list is correct (i.e. there are 5 parents in the JSON string, and there are 5 Parent objects in the parents List). However, all their attributes are not there, and the child tree are missing as well.

I’d tried numerous configuration, including remove the extended class and put all the id and name in the respective classes but the result is still the same.

Anyone can give me any pointer that where did i go wrong?

Thanx a bunch!

  • 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-05-30T16:18:52+00:00Added an answer on May 30, 2026 at 4:18 pm

    Your JSON and Java class mismatch.

    Lets read

    {"parents":[
        {"parent":{
                "id":1,
                "name":"Sam",
                "childs":[
                    {
                        "child":{
                            "id":1,
                            "name":"Alice",
                            "books":[
                                {
                                    "book":{
                                        "id":1,
                                        "name":"Alice in Wonderland"
                                    }
                                }
                            ]
                        }
                    }
                ]
            } 
    
        }    
    ]}
    

    Your top object has a List of class that has parents as it’s attribute. Your Java class Container has parents attribute. Good.

    Now this list parents is a List of objects that has parent attribute. Does your Parent object has parent attribute? No.

    Go further down, each Parent has id, name, and a List of objects as childs (children, should be) attribute that has child attribute, does your Child class has it? No.

    Similarly, goes for books.

    Did you try your classes on JSON like

    {"parents":[
            {
                "id":1,
                "name":"Sam",
                "childs":[
                        {
                            "id":1,
                            "name":"Alice",
                            "books":[
                                {
                                        "id":1,
                                        "name":"Alice in Wonderland"
                                }
                            ]
                        }
    
                ]
            }  
    ]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a bit difficult to explain in writing, so please bear with
This might be a bit like asking how long a length of string is,
This is going to be a bit long and specific so please bear with
This question might be a bit long and specific, but I have been attempting
This might be a bit on the silly side of things but I need
This might be a bit of a silly question but; If I have two
Ok this might be a bit of hack but bear with me :) The
OK, this might sound a bit confusing and complicated, so bear with me. We've
EDIT seems my original post below might have been a bit long. Simply said,
This post might be a bit long, but if you think you can help,

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.