Java Jaxb:IllegalAnnotationExceptions
我收到以下异常“1次Java Jaxb:IllegalAnnotationExceptions,java,xml,jaxb,Java,Xml,Jaxb,我收到以下异常“1次IllegalAnnotationExceptions” 代码: Image image = new Image("url"); StringWriter sw = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(Image.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshalle
IllegalAnnotationExceptions
”
代码:
Image image = new Image("url");
StringWriter sw = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(Image.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(image, sw);
类别:
@XmlRootElement(name="ProductImage")
public class Image {
private String url;
public Image( String url) {
this.url = url;
}
@XmlElement(name = "ImageLocation")
public String getUrl() {
return this.url;
}
}
我尝试在字段上设置@xmlement
注释,并在类上设置AccessorType字段。但我也有同样的例外
我缺少默认构造函数。 公众形象(){ }使用这个类
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name="ProductImage")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(name = "ProductImage", propOrder = {
"url"
})
public class Image {
public Image(){}
private String url;
public Image( String url) {
this.url = url;
}
@XmlElement(name = "ImageLocation")
public String getUrl() {
return this.url;
}
}
生成的XML是
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProductImage>
<ImageLocation>url</ImageLocation>
</ProductImage>
网址
您得到的异常的堆栈跟踪是什么?