我遇到了以下异常:"1个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;
}
}
我尝试在字段上设置@XmlElement
注解,并在类上设置AccessorType Field,但是我仍然遇到了相同的异常。
我缺少默认构造函数。 public Image () { }