错误 error.GrailsExceptionResolver - 无法引用隐式元素
当我尝试使用 Xstream 封送我的常规域类 Employee 之一时,出现以下错误。 Employee有很多empeeDesiredSkills,分别属于Skill和Employee
这里是相关的Xstream代码
employeeInstance = new Employee();
XStream xstream = new XStream();
Xstream.alias("employee", Employee.class);
String xml = xstream.toXML(employeeInstance);
Employee类将employeeDesiredSkills显式定义为ArrayLists。我不太确定错误消息说的是什么。我只知道“C 开发”是数据库中保存为 EmployeeDesiredSkill 的项目之一
2010-09-21 18:13:13,911 [http-8080-1] ERROR errors.GrailsExceptionResolver - Cannot reference implicit element
---- Debugging information ----
implicit-element : C Development
referencing-element : /employee/employeeDesiredSkills/storedSnapshot/EmployeeDesiredSkill/skill/roleSkills/owner
-------------------------------
com.thoughtworks.xstream.core.AbstractReferenceMarshaller$ReferencedImplicitElementException: Cannot reference implicit element
---- Debugging information ----
implicit-element : C Development
referencing-element : /employee/employeeDesiredSkills/storedSnapshot/EmployeeDesiredSkill/skill/roleSkills/owner
-------------------------------
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)
I am getting the below error when I try to use Xstream to marshal one of my groovy domain classes Employee. Employee hasmany employeDesiredSkills, which belongsTo Skill and Employee
Here is the relevant Xstream code
employeeInstance = new Employee();
XStream xstream = new XStream();
Xstream.alias("employee", Employee.class);
String xml = xstream.toXML(employeeInstance);
Employee class has the employeeDesiredSkills explicity defined as ArrayLists. I'm not real sure what error message is saying. I just know that "C Development" was one of the items saved as an EmployeeDesiredSkill in the database
2010-09-21 18:13:13,911 [http-8080-1] ERROR errors.GrailsExceptionResolver - Cannot reference implicit element
---- Debugging information ----
implicit-element : C Development
referencing-element : /employee/employeeDesiredSkills/storedSnapshot/EmployeeDesiredSkill/skill/roleSkills/owner
-------------------------------
com.thoughtworks.xstream.core.AbstractReferenceMarshaller$ReferencedImplicitElementException: Cannot reference implicit element
---- Debugging information ----
implicit-element : C Development
referencing-element : /employee/employeeDesiredSkills/storedSnapshot/EmployeeDesiredSkill/skill/roleSkills/owner
-------------------------------
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于异常,您的
Employee
元素可能有一个需要在XStream
对象中显式指定别名的字段。我无法提供任何具体建议,因为我对您的领域和环境不太了解。但是,您可以尝试弄乱别名,直到一切正常为止。
作为调试方法,您可以尝试使用 XStream 的
omitField()
在所有Employee
属性上,然后一次删除一个,直到找到哪个一个是造成问题的原因。您可以从那里向下钻取。Given the Exception, it looks like your
Employee
element may have a field that needs to be aliased explicitly in yourXStream
object.I can't offer any concrete suggestions as I don't have a great understanding of your domain and environment. However, you might try messing with the aliasing until you get things right.
As a debugging method, you might try using XStream's
omitField()
on ALL of theEmployee
properties and then remove them one at a time until you find out which one is causing the problem. You can drill down from there.