I am having an issue with my unmarshaller. I have a file that looks like the following:
<Employee xmlns="namespace here"> <Employee> <Id>2</Id> <Name>idk</Name> </Employee> </Employee> The problem is the root element and the list of elements are the same name "Employee". When I go to unmarshal I get a classcastexception.
@XmlRootElement(name="Employee") public class EmployeeInformation { List<EmployeeInformationElement> elements; private String errorCode; private String errorMessage; public List<EmployeeInformationElement> getElements() { return elements; } @XmlElement(name="Employee") public void setElements(List<EmployeeInformationElement> elements) { this.elements = elements; } public String getErrorCode() { return errorCode; } @XmlElement(name="ErrorCode") public void setErrorCode(String errorCode) { this.errorCode = errorCode; } public String getErrorMessage() { return errorMessage; } @XmlElement(name="ErrorMessage") public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } I am able to use this code to marshal a file that looks exactly like the file I need to unmarshal. So I am confused. What is missing so when I unmarshal, the unmarshaller does not give me the following exception:
java.lang.ClassCastException: XXXX.EmployeeInformationElement cannot be cast to XXXX.EmployeeInformation
No comments:
Post a Comment