java - Jaxb : IllegalAnnotationExceptions -


i getting following exception "1 counts of illegalannotationexceptions"

code:

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); 

class:

@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;     } } 

i tried setting @xmlelement annotation on field , setting accessortype field on class. getting same exception.


i missing default constructor. public image () { }

use class..

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 generated

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <productimage>     <imagelocation>url</imagelocation> </productimage> 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -