作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试使用 Xstream 来编码我的常规域类 Employee 时,出现以下错误。 Employee有很多employeeDesiredSkills,分别属于Skill和Employee
这是相关的Xstream代码
employeeInstance = new Employee();
XStream xstream = new XStream();
Xstream.alias("employee", Employee.class);
String xml = xstream.toXML(employeeInstance);
Employee 类将employeeDesiredSkills 显式定义为ArrayList。我不太确定错误消息说的是什么。我只知道“C Development”是数据库中保存为 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)
最佳答案
考虑到异常,您的 Employee
元素可能有一个需要在 XStream
对象中显式指定别名的字段。
我无法提供任何具体建议,因为我对您的领域和环境不太了解。但是,您可以尝试弄乱别名,直到一切正常为止。
作为调试方法,您可以尝试使用 XStream 的 omitField()
在所有 Employee
属性上,然后一次删除一个属性,直到找出导致问题的属性。您可以从那里向下钻取。
关于java - 错误 error.GrailsExceptionResolver - 无法引用隐式元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3764938/
我是一名优秀的程序员,十分优秀!