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
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
Here is such an example, using the same JSON as in the original question.