gpt4 book ai didi

java - 错误 error.GrailsExceptionResolver - 无法引用隐式元素

转载 作者:行者123 更新时间:2023-12-01 05:53:45 26 4
gpt4 key购买 nike

当我尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com