saving twitter4J Status to MongoDB gives "twitter4j.Status is an interface, and JAXB can't handle interfaces"

StackOverflow https://stackoverflow.com/questions/18490707

Question

Trying to save a List<Status> to MongoDB (via Morphia), and I get this compile time error:

com.sun.xml.ws.spi.db.DatabindingException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
twitter4j.Status is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at twitter4j.Status
        at public java.util.List Model.TwitterJob.getStatuses()

Any idea? Thanks a lot!

Was it helpful?

Solution

It's a little complicated to marshal Status, because the class StatusJSONImpl which implements Status in Twitter4j 3.0 is protected. You need to override the class and make it visible to your classes.

Please checkout the following example for detail.

https://github.com/phstudy/Twitter4j_JAXB_example

OTHER TIPS

You can use the @XmlElement annotation to specify an implementing class of the Status interface.

@XmlElement(type=SomeStatusImpl.class)
public List<Status> getStatuses() {
    return statuses;
}

For More Information

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top