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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:21:07+00:00 2026-05-23T06:21:07+00:00

I have a web service class that successfully pulls my JSON from a feed

  • 0

I have a web service class that successfully pulls my JSON from a feed into a String. I want to use Gson to parse it into a List of a custom class, but the parsing messes up somehow.

Right now the code that does the parsing looks like this:
http://pastie.org/2079115.
The JSON is included.

I believe the issue occurs because of that extra layer of

"article": { ... }, "article": { ... } ...

Pretty much everything I can find online tells me to do it like the above, including the Gson API.

The issue is that the articles variable ends up as a list with the correct number of Articles, but all of the data in each Article is null. I’ve toyed with the structure of

Type collectionType = new TypeToken<ArrayList<Article>>(){}.getType;

but any changes just ends up in the articles variable being null and not even holding null Articles. Any idea where to go from here?

For reference, my Article.java looks like this:
http://pastie.org/2079165

  • 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-23T06:21:08+00:00Added an answer on May 23, 2026 at 6:21 am

    The problem is that JSON structure does not match the Java structure attempting to be deserialized into, and no custom deserialization processing to handle the mismatch is provided. So, yes, “the issue occurs because of that extra layer”.

    A simple solution would be to change the Java structure to match the JSON structure. The JSON structure is

    an array of 
        an unnamed object with 
            one element named article with value of
                an object with 
                    seven elements named author_id, body, catagory, created_at, id, published, updated_at
    

    Here is such an example, using the same JSON as in the original question.

    import java.io.FileReader;
    import java.lang.reflect.Type;
    import java.util.ArrayList;
    
    import com.google.gson.Gson;
    import com.google.gson.reflect.TypeToken;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        Gson gson = new Gson();
        Type collectionType = new TypeToken<ArrayList<ArticleContainer>>() {}.getType();
        ArrayList<ArticleContainer> articles = gson.fromJson(new FileReader("input.json"), collectionType);
        System.out.println(gson.toJson(articles));
      }
    }
    
    class ArticleContainer
    {
      Article article;
    }
    
    class Article
    {
      public int author_id;
      public String body;
      public String catagory;
      public String created_at;
      public int id;
      public String published;
      public String updated_at;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service class that the rest of the framework depends on
I have a WCF Web Service which is referenced from a class library. After
I have web service, which use integrated security in IIS. Now, I want to
I have a web service class diagram, I want it to show what stored
We have a Web Service implementation that throws a custom SecurityException . public class
I Have a web service implementation class in java and I use wsgen to
I have a web service and multiple clients that will use it. A MVC
I have a web service , i add some extra class which have message
I have a class which calls out to an existing web service. My class
I have a class library (.NET) with a reference to a web service (in

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.