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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:58:43+00:00 2026-06-05T13:58:43+00:00

I am writing my first android app and have very limited experience in parsing

  • 0

I am writing my first android app and have very limited experience in parsing Json data back into POJO’s. I am using GSON, and its mathod fromJson(). It is working somewhat but not all the classes are getting made.

The class i am serializing is

public class User  extends Model
{
   public String id;
   public String name;
   public List<User> friends = new ArrayList<User>();
   public List<Match> matches = new ArrayList<Match>();
}

Is it possible to parse the User into a class called User. but the List of Users into another Class with a different name and with much less parameters

  • 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-05T13:58:44+00:00Added an answer on June 5, 2026 at 1:58 pm

    Create and register a type adapter for List. Creating it looks something like this:

    private final TypeAdapter<List<User>> listOfUsersTypeAdapter = new TypeAdapter<List<User>>() {
        @Override public void write(JsonWriter out, List<User> value) throws IOException {
            out.beginArray();
            for (User user : value) {
                out.value(user.id);
            }
            out.endArray();
        }
        @Override public List<User> read(JsonReader in) throws IOException {
            in.beginArray();
            List<User> result = new ArrayList<User>();
            while (in.hasNext()) {
                User user = new User();
                user.id = in.nextString();
            }
            in.endArray();
            return result;
        }
    }.nullSafe();
    

    And register it when you create your Gson object:

        Gson gson = new GsonBuilder()
            .registerTypeAdapter(new TypeToken<List<User>>() {}.getType(), listOfUsersTypeAdapter)
            .create();
    

    I haven’t tested this but it should work. Note that when you deserialize your users won’t have any of their friends or matches fields filled in. You can reconstruct that from the graph in a post-processing step. Or use GraphAdapterBuilder to do it automatically.

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

Sidebar

Related Questions

I am currently writing my first Android app and have based most of my
To begin with, this is the first Android app I'm writing, and I have
I've been writing my first android app and so far have just been building
I'm writing my first 2D app for Android using OpenGL. I'm writing it on
I am writing an app and I have run into a problem. The first
I am writing my first Android app. I have three Activities: BaseballCardList, BaseballCardDetails, and
Im new to android. I have been writing my first app, I testing it
I'm writing my first android app (I'm a noob at android, but decent at
Hurro! I'm trying my hand at writing my first Android app, and I've hit
I'm writing my first location based android app, but got confused about some of

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.