使用JAXB和扩展的xmlAttributes

时间:2017-12-28 11:51:43

标签: java xml jaxb unmarshalling

我想用JAXB解组一个xml文件。 问题是我想扩展一个具有xmlAttribues的其他类,但我总是得到一个IllegalAnnotationException。

我想取消这样的事情:

       <text
           font-size="22"
           font-name="Arial"
           font-underline="false"
           font-italic="false"
           font-color="black"
           font-bold="true"
           text-align="center">
         <![CDATA[Test]]>
       </text>

这是我的代码: Text.class

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Text extends StyleSettings{

    @XmlValue
    @XmlJavaTypeAdapter(CDATAAdapter.class)
    private String value;

    public Text() {
    }

    public String getValue() {
        return value;
    }
}

StyleSettings.class

@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class StyleSettings {


@XmlAttribute(name = "font-name")
private String fontName;
@XmlAttribute(name = "font-size")
private Double fontSize;
@XmlAttribute(name = "font-color")
private String fontColor;
@XmlAttribute(name = "font-italic")
private Boolean fontItalic;
@XmlAttribute(name = "font-bold")
private Boolean fontBold;
@XmlAttribute(name = "font-underline")
private Boolean fontUnderline;
@XmlAttribute(name = "text-align")
private String textAlign;
...
// only getter and setter

我希望你能理解我的问题并找到解决方案。

谢谢

B4chi

15:16:59.151 [main] ERROR de.b4chi.reporting.word.WordReportingWithAspose - 
Failed to unmarschal xml file.
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of 
IllegalAnnotationExceptions
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:405)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:253)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:84)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:247)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:234)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:441)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:641)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584)
at 
de....WordReportingWithAspose.unmarshal(WordReportingWithAspose.java:70)
atde....WordReportingWithAspose.startGenerating(WordReportingWithAspose.java:48) at 
de....WordReportingWithAspose.main(WordReportingWithAspose.java:39)
15:16:59.153 [main] ERROR de.b4chi.reporting.word.WordReportingWithAspose - 
Faild to unmarshal xml file.

0 个答案:

没有答案