使用 JAXB 解组
我是 java 新手(来自 c#.net 背景),并尝试使用上面的示例来编组和解组。
按照下面的链接 使用 JaxB 编组实现通用接口的对象列表
使用 Blaise Doughan 先生提到的上述技术,我能够将 java 对象封送到 xml。但是,当我保存此 xml 并尝试将 xml 解组回 java 对象时,我在控制台上看到以下内容:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException:2 IllegalAnnotationException 的计数 @javax.xml.bind.annotation.XmlElementRef 注释在两个上找到 地方;一个就足够了。这个问题与以下内容有关 位置:@javax.xml.bind.annotation.XmlElementRef(name=##default, 必需=true,类型=类 javax.xml.bind.annotation.XmlElementRef$DEFAULT, 命名空间=) 在公共 java.util.List Community.getPeople() 在 Community 这个问题是 与以下位置相关:位于 @javax.xml.bind.annotation.XmlElementRef(name=##default, 必需=true,类型=类 javax.xml.bind.annotation.XmlElementRef$DEFAULT, 命名空间=) 在公共 void Community.setPeople(java.util.List) 在社区....
注意:我为 Class Boy 和 Class Girl 创建了 getter/setter 来实现解组。
I am new to java (coming from c#.net background) and was trying the above example to marshal and unmarshal.
Following the link below
Marshalling a List of objects implementing a common interface, with JaxB
using the above technique as mentioned by Mr.Blaise Doughan, I was able to marshal the java objects to xml. But when i save this xml and try to unmarshal the xml back to java object i get the following on the console:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2
counts of IllegalAnnotationExceptions
@javax.xml.bind.annotation.XmlElementRef annotation is found on two
places; one would be suffice. this problem is related to the following
location: at @javax.xml.bind.annotation.XmlElementRef(name=##default,
required=true, type=class
javax.xml.bind.annotation.XmlElementRef$DEFAULT, namespace=) at public
java.util.List Community.getPeople() at Community this problem is
related to the following location: at
@javax.xml.bind.annotation.XmlElementRef(name=##default,
required=true, type=class
javax.xml.bind.annotation.XmlElementRef$DEFAULT, namespace=) at public
void Community.setPeople(java.util.List) at Community ....
Note : I have created getters/setters for Class Boy and Class Girl for implementing unmarshalling.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您可能已经注释了 getPeople 和 setPeople 方法。 JAXB(和其他 Java EE 技术)只需要您注释一个。
了解更多信息
It appears that you may have annotated both the getPeople and setPeople methods. JAXB (and other Java EE technologies) only require you annotate one.
For More Information
如果您展示了代码,那么提供帮助会更容易...
问题似乎是,您有 getter 和 setter,这让 JAXB 感到困惑,因为它不知道如何使用它们来解组 xml。
尝试使用
FIELD
访问类型:It's easier to help, if you showed your code...
The problems seems to be, that you have getters and setters and which confuses JAXB, because it does not know how to use them to unmarshal the xml.
Try to use
FIELD
access type: