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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:27:29+00:00 2026-06-18T23:27:29+00:00

i am new on JSON and have a problem on creating POJO for followed

  • 0

i am new on JSON and have a problem on creating POJO for followed JSON input.

    [
    {
"score":1,
"popularity":3,
"name":"Brad Pitt",
"id":287,
"biography":"test",
"url":"http://www.themoviedb.org/person/287",
"profile":[
    {
        "image":{
            "type":"profile",
            "size":"thumb",
            "height":68,
            "width":45,
            "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w45/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg",
            "id":"4ea5cb8c2c0588394800006f"
        }
    },
    {
        "image":{
            "type":"profile",
            "size":"profile",
            "height":281,
            "width":185,
            "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w185/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg",
            "id":"4ea5cb8c2c0588394800006f"
        }
    },
    {
        "image":{
            "type":"profile",
            "size":"h632",
            "height":632,
            "width":416,
            "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/h632/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg",
            "id":"4ea5cb8c2c0588394800006f"
        }
    },
    {
        "image":{
            "type":"profile",
            "size":"original",
            "height":1969,
            "width":1295,
            "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/original/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg",
            "id":"4ea5cb8c2c0588394800006f"
        }
    }
],
"version":685,
"last_modified_at":"2013-02-16 07:11:15 UTC"
  }
  ]

i have created three POJO’s for this one of them is main person class and this one contains profile object also. Profile object returns image list.:

    public class Person implements Serializable {

  private static final long serialVersionUID = 6794898677027141412L;

  public String biography;
  public String id;
  public String last_modified_at;
  public String name;
  public String popularity;
  public String score;
  public String url;
  public String version;
  public ArrayList<Profile> profile;

  //getters and setters
    }

    public class Profile implements Serializable {

  private static final long serialVersionUID = -6482559829789740926L;

  public ArrayList<Image> image;

    }


    public class Image implements Serializable {

    private static final long serialVersionUID = -2428562977284114465L;

    public String type;
    public String url;
    public String size;
    public int width;
    public int height;
    }

to retrieve data i am using gson:

  Gson gson = new Gson();
  Type collectionType = new TypeToken<List<Person>>(){}.getType();
  List<Person> details = gson.fromJson(json, collectionType);

when i run this i got:

  02-17 11:04:50.531: E/AndroidRuntime(405): Caused by:  com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3

updated Image POJO:

public class Image implements Serializable {

private static final long serialVersionUID = -2428562977284114465L;
private Object image;

public class ImageInner {

    public static final String SIZE_ORIGINAL = "original";
    public static final String SIZE_MID = "mid";
    public static final String SIZE_COVER = "cover";
    public static final String SIZE_THUMB = "thumb";
    public static final String TYPE_PROFILE = "profile";
    public static final String TYPE_POSTER = "poster";
    public String type;
    public String url;
    public String size;
    public int width;
    public int height;

}
}

thank you

  • 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-18T23:27:30+00:00Added an answer on June 18, 2026 at 11:27 pm

    Your code is actually really close, with two errors:

    1) The error you’re receiving is telling you that at the very beginning of the JSON it was expecting the start of an array ([) , but got the start of an object ({) instead. The JSON you have posted is not what you’re feeding Gson (see below).

    2) When you correct the above, you have one small problem in your Person POJO:

    public ArrayList<Profile> profile;
    

    should be:

    public ArrayList<Image> profile;
    

    You actually don’t need your Profile class; profile in the JSON is an array. As-is you would receive another error similar to what you’re receiving now because it would be expecting an ArrayList of Profile objects: "profile":[{"image":[{imageobject},...]},{"image":[{imageobject},...]}]

    If you fix number two and feed Gson the JSON you have posted, it works perfectly. You’ve posted an array of Person objects but what you actually have in your code (in json) is either just one object … or an object that contains the array you have posted. The small example below works perfectly (after correcting your Person class):

    public class App
    {
            static String json = "[{\"score\":1,\"popularity\":3,\"name\":\"Brad Pitt\",\"id\":287," +
            "\"biography\":\"test\",\"url\":\"http://www.themoviedb.org/person/287\",\"profile\":" +
            "[{\"image\":{\"type\":\"profile\",\"size\":\"thumb\",\"height\":68,\"width\":45,\"url\":" +
            "\"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w45/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg\"," +
            "\"id\":\"4ea5cb8c2c0588394800006f\"}},{\"image\":{\"type\":\"profile\",\"size\":\"profile\"," +
            "\"height\":281,\"width\":185,\"url\":\"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w185/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg\"," +
            "\"id\":\"4ea5cb8c2c0588394800006f\"}},{\"image\":{\"type\":\"profile\",\"size\":\"h632\",\"height\":632,\"width\":416,"+
            "\"url\":\"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/h632/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg\"," +
            "\"id\":\"4ea5cb8c2c0588394800006f\"}},{\"image\":{\"type\":\"profile\",\"size\":\"original\",\"height\":1969," +
            "\"width\":1295,\"url\":\"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/original/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg\"," +
            "\"id\":\"4ea5cb8c2c0588394800006f\"}}],\"version\":685,\"last_modified_at\":\"2013-02-16 07:11:15 UTC\"" +
            "}]";
    
        public static void main(String[] args)
        {
    
            Gson gson = new Gson();
            Type collectionType = new TypeToken<List<Person>>(){}.getType();
            List<Person> details = gson.fromJson(json, collectionType);
        }
    }
    

    Edit to add: You actually have some type conversions going on that Gson is handling for you … but you may not really want. For example in your JSON score is an int but in your POJO you’ve made it a String. Gson silently does the conversion.

    Also, simply creating a SSCCE (http://sscce.org/) like what I did above can help you debug these issues.

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

Sidebar

Related Questions

I have a problem accessing JSON data. I'm new to JSON and jquery so
i have this JSON: var projects_array = new Array( {name:myName1, id:myid1, index:1}, {name:myName2, id:myid2,
I have a problem creating a mapping for a json that i want to
I have a problem creating an input validation hash. JavaScript submits data to API
am new to Json so a little green. I have a Rest Based Service
I am very new to Python and I have a json news feed that
I am pretty new to YUI and need some help. I have a JSON
I have: localStorage.xxx = JSON.stringify([[something,hello],[something2,hello2]]); . How can i add a new array in
I'm new to jquery and JSON. I have the following JSON structure. { address:{
I have this code: $coder = JSON::XS->new->utf8->pretty->allow_nonref; %perl = $coder->decode ($json); When I write

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.