2011-11-07 35 views
2

这就是我想要做的事:抽象类的XmlRootElement注释 - 可能吗?

@XmlRootElement(name = "bar") 
@XmlAccessorType(XmlAccessType.NONE) 
public abstract class Bar { 
} 

public final class Foo extends Bar { 
    @XmlElement 
    public String getMsg() { 
     return "hello, world!"; 
    } 
} 

现在我想马歇尔Foo类的一个实例:

com.sun.istack.SAXException2: unable to marshal type "Foo" as 
an element because it is missing an @XmlRootElement annotation 

什么是解决方法吗?

回答

2

如果没有超类的@XmlRootElement注解,你可以离开吗?相反,你应该把它放在你的每个子类中。 JAX-B仍然会知道超类字段。