Derek Derek - 1 month ago 6
Java Question

ERROR errors.GrailsExceptionResolver - Cannot reference implicit element

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)

Answer

Given the Exception, it looks like your Employee element may have a field that needs to be aliased explicitly in your XStream 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 the Employee 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.

Comments