Closed AE9999 closed 10 years ago
Hey AE9999,
So the easiest fix for this would probably be to do what is done in RedditMessage and simply
@JsonIgnoreProperties(ignoreUnknown = true)
OR
You could add a new field in the RedditMore
object for subreddit_id
with a respective setter & getter, and that should fix the problem as well.
I find it very strange that the TestNG integration test has'nt encountered this issue yet - perhaps the Reddit API has been updated? The JSON example for more does not mention this attribute.
I confirm that adding @JsonIgnoreProperties(ignoreUnknown = true) to RedditMore.java fixes the problem
Assume that in the following code ConnectionManager.getDefaultRedditConnection(); Returns a logged in reddit object. The running the following main method results in the below error
-------------Code------------- package testpackage
import java.util.List;
import com.cd.reddit.Reddit; import com.cd.reddit.RedditException; import com.cd.reddit.json.mapping.RedditComment; import com.cd.reddit.json.mapping.RedditLink; import com.cd.reddit.json.util.RedditComments;
public class App { public static void main( String[] args ) throws RedditException { Reddit reddit = ConnectionManager.getDefaultRedditConnection(); //List results = reddit.subreddits("new");
//for (RedditSubreddit res : results) {
// System.out.println(res.toString());
//}ing
//List linkRes = reddit.listingFor(swtorId, cats);
List links = reddit.listingFor( "swtor", "hot");
for (RedditLink link : links) {
System.out.println(link.toString());
System.out.println();
// Tested: link.getId()
//
RedditComments comments = reddit.commentsFor("swtor",
link.getId() );
for(RedditComment comment : comments.getComments()) {
System.out.println("\t==>" + comment.toString());
}
}
}
}
-------------ERROR-------------
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:724)
Caused by: com.cd.reddit.RedditException: Unrecognized field "subreddit_id" (Class com.cd.reddit.json.mapping.RedditMore), not marked as ignorable
at [Source: N/A; line: -1, column: -1](through reference chain: com.cd.reddit.json.mapping.RedditMore["subreddit_id"])
at com.cd.reddit.json.jackson.RedditJsonParser.mapJsonComments(RedditJsonParser.java:335)
at com.cd.reddit.json.jackson.RedditJsonParser.parseComments(RedditJsonParser.java:111)
at com.cd.reddit.Reddit.commentsFor(Reddit.java:220)
at com.keystone.word.workers.App.main(App.java:32)
... 6 more
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "subreddit_id" (Class com.cd.reddit.json.mapping.RedditMore), not marked as ignorable
at [Source: N/A; line: -1, column: -1](through reference chain: com.cd.reddit.json.mapping.RedditMore["subreddit_id"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1999)
at com.cd.reddit.json.jackson.RedditJsonParser.mapJsonComments(RedditJsonParser.java:333)