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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:29:11+00:00 2026-05-29T09:29:11+00:00

I have a json string like this: http://pastebin.com/ckUZadwL I’m trying to use gson to

  • 0

I have a json string like this:
http://pastebin.com/ckUZadwL

I’m trying to use gson to parse them. However, I have a question. In new reponse, the user element contains generic id as the key, and since it’s in the inner class, I’m not sure how to parse it.

Thank you for your help.

Here are a few class containers I build to store there data:

public class CometCallback
{
    public int new_offset;
    public Data[] data;
}

public class Data
{
    public long plurk_id;
    public int response_count;
    public Response response;
    public UserInfo user; 
    public String type;
    public Plurk plurk;
}

public class Response
{
    public String lang;
    public String content_raw;
    public long user_id;
    public String qualifier;
    public long plurk_id;
    public String content;
    public long id;
    public String posted;
}

public class Plurk extends Response
{
    public Object[] replurkers;
    public int responses_seen;
    public int replurkers_count;
    public String replurker_id;
    public int response_count;
    public boolean replurkable;
    public Object limited_to;
    public int favorite_count;
    public int is_unread;
    public Object[] favorers;
    public int plurk_type;
    public boolean replurked;
    public boolean favorite;
    public int no_comments;
    public long owner_id;
}
  • 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-29T09:29:12+00:00Added an answer on May 29, 2026 at 9:29 am

    I have several thing to share about you post:

    1. The biggest problem you will face is that the user has very weird
      json serialization – its id is used as key. The only way I can think of is to use enableComplexMapKeySerialization option of the GsonBuilder. Then you will need to declare UsewrInfo as containing only one element Map<Integer, User> and declare the User bean with all the attributes mapped to the id.

    2. I suppose you know that with gson it is not required to have the
      class field names matching the keys in the gson. E.g you can still
      use a camel-cased newOffset and parse in it the field new_offset.
      You just need to place the gson annotation
      @SerializedName("new_offser") above the declaration of the field.

    3. Here is how you do the deserialization from json using gson. It is
      really straight forward:

      Gson gson = new GsonBuilder()
          .enableComplexMapKeySerialization()
          .serializeNulls()
          .setDateFormat(MY_DATE_FORMAT)
          .create();
      CometCallback cometCallback = gson.fromJson(jsonFile, CometCallback.class) ;
      

      I will discuss on the option of DateFormat in the next section.
      serializeNulls is needed, because I saw the attributes with null
      values are also serialized like "date_of_birth": null.

    4. About the DateFormat – I saw you declare public String posted;
      as string. However gson can parse the dates straight out of the json
      string for you as long as you specify the exact format the dates
      will be in. Here is the exact format I think you define your dates
      in:

      public static final SimpleDateFormat MY_DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
      

      Now declaring this and passing it in the
      setDateFormat(MY_DATE_FORMAT) method you should be able to change
      all your dates to be read as dates and gson will parse them for you.

    5. By the way, I suppose you know it, but you can deserialize json
      arrays to lists for example. This happens by just declaring the
      fields accordingly and gson automagically will store in them.

    Hopefully all this will help you deserialize your data. Happy coding!

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

Sidebar

Related Questions

Under this link : http://dev1.gecoloco.com/rte/done_json.php I have a json-like object, that I'm operating on.
I have a JSON String like this $test='{var1:null,var3:null,status:{code:150,message:blah blah}}'; I want to access the
I want to parse this JSON string using Gson {name:name,type:[a,b,c]} is it possible? 1st
I have json string from here: http://vkontakte.ru/al_video.php?act=load_videos_silent&al=1&oid=8046830 I use Touch json parser. //received json
I have a Restlet Service that looks like this: @POST @Produces(application/json) public String processImmediately(String
I have a long string from android Http get like this: {movies:[ {movieId:fmen71229238,eTitle:Mission: Impossible
I have converted my Datatable to json string use the following method... public string
I have some JSON returned to the browser like this product: { Title: School
I have a JAX-RS resource, which gets its paramaters as a JSON string like
lets say I have a String like this [{ name : Ronald , firstname

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.