[英]Unmarshalling Error Jaxb - “Class does not have a default no arg constructor” while having a default no args constructor
I'm trying to unmarshal the following XML but getting an exception: "1 counts of IllegalAnnotationExceptions EntityVersionInfo does not have a no-arg default constructor." 我试图解组以下XML,但遇到异常:“ 1个IllegalAnnotationExceptions EntityVersionInfo计数没有无参默认构造函数。” despite actually having a no args constructor.
尽管实际上没有args构造函数。 What am I missing?
我想念什么?
XML: XML:
<topLevelObject>
<entityVersionInfo>
<id>111111</id>
<version>1</version>
</entityVersionInfo>
</topLevelObject>
Entities in Java with Annotations: Java中带注释的实体:
TopLevelObject: TopLevelObject:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "topLevelObject")
public class TopLevelObject {
@XmlElement(name = "entityVersionInfo")
private EntityVersionInfo versionInfo;
public TopLevelObject() {
//no args constructor
}
//GETTERS AND SETTERS HERE...
}
EntityVersionInfo: EntityVersionInfo:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "entityVersionInfo")
public class EntityVersionInfo {
@XmlElement(name = "id")
private String id;
@XmlElement(name = "version")
private String version;
public EntityVersionInfo() {
//no arg constructor
}
//GETTERS AND SETTERS
}
Adding this to EntityVersionInfo 将此添加到EntityVersionInfo
@Override
public String toString() {
return "EntityVersionInfo [id=" + id + ", version=" + version + "]";
}
Adding this to TopLevelObject 将此添加到TopLevelObject
@Override
public String toString() {
return "TopLevelObject [versionInfo=" + versionInfo + "]";
}
Running this test I get: 运行此测试,我得到:
JAXBContext context = JAXBContext.newInstance(TopLevelObject.class);
Unmarshaller u = context.createUnmarshaller();
Reader reader = new StringReader(
"<topLevelObject>\r\n" +
" <entityVersionInfo>\r\n" +
" <id>111111</id>\r\n" +
" <version>1</version>\r\n" +
" </entityVersionInfo>\r\n" +
"</topLevelObject>");
Object o = u.unmarshal(new InputSource(reader ));
System.out.println(o);
I get : 我得到:
TopLevelObject [versionInfo=EntityVersionInfo [id=111111, version=1]]
So your entity code is good, maybe you have more then one EntityVersionInfo class in your project or something else, but entities are good. 因此,您的实体代码很好,也许您的项目中有一个以上的EntityVersionInfo类或其他类,但是实体很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.