Mapping xml to java Object using XmlPath



Below are the classes



@XmlRootElement(name = "response")
@XmlAccessorType(XmlAccessType.FIELD)
public class Response {
@XmlElement(name = "result")
private Result result;
}

@XmlAccessorType(XmlAccessType.FIELD)
public class Results {

@XmlElement(name="doc")
private List<Doc> docs;
}

@XmlAccessorType(XmlAccessType.FIELD)
public class Doc {

@XmlPath("int[@name='DOWNLOADCOUNT']/text()")
private int count;
@XmlPath("str[@name='TITLE']/text()")
private String title;
@XmlPath("str[@name='LANGUAGE']/text()")
private String language;
@XmlPath("str[@name='ALBUM']/text()")
private String album;
@XmlPath("str[@name='VODAFONERBTID']/text()")
private String telRBTId;
@XmlPath("arr[@name='SINGER']/str/text()")
private String[] singers;
@XmlPath("float[@name='score']/text()")
private float score;
}


Here is the exception which I am getting


[Exception [EclipseLink-25008] (Eclipse Persistence Services - 2.5.0.v20130425-368d603): org.eclipse.persistence.exceptions.XMLMarshalException Exception Description: A descriptor with default root element response was not found in the project] at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:980) at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:126) at com.sharique.application.Application.unMarshalling(Application.java:44) at com.sharique.main.TestMain.main(TestMain.java:53)


No comments:

Post a Comment