1

当我尝试使用 Xstream 编组我的一个 groovy 域类 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 明确定义为ArrayLists。我不确定错误消息在说什么。我只知道“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)
4

1 回答 1

0

鉴于异常,看起来您的Employee元素可能有一个需要在XStream对象中显式别名的字段。

我无法提供任何具体建议,因为我对您的领域和环境没有深入了解。但是,您可能会尝试弄乱别名,直到您做对为止。

作为一种调试方法,您可以尝试omitField()在所有Employee属性上使用 XStream,然后一次删除一个,直到找出导致问题的原因。您可以从那里向下钻取。

于 2010-09-22T00:37:40.447 回答