I have an XML file like below, and I want to convert it into a Java object.
<P1>
<CTS>
Hello
</CTS>
<CTS>
World
</CTS>
<P1>
So I created the following Java classes with their properties.
P1 class
@XmlRootElement
public class P1 {
@XmlElement(name = "CTS")
List<CTS> cts;
}
CTS class
public class CTS {
String ct;
}
Test Class
File file = new File("D:\\ContentTemp.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(P1.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
P1 p = (P1) jaxbUnmarshaller.unmarshal(file);
But I am getting the following error:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException:
2 counts of IllegalAnnotationExceptions
Class has two properties of the same name "cts"