| « Preventing remote attacks on your server | Create a new mailing list in Horde webmail » |
Supplied root object of class * cannot be marshalled without top-level mapping
April 22nd, 2009Came up against a problem with (JibX) marshalling an object down to XML. Part of the problem was not finding any reference to what the error message means. So for future generations I’ve documented it here. The error message is:
org.springframework.oxm.jibx.JibxMarshallingFailureException: JiBX marshalling exception: Supplied root object of class java.util.LinkedList cannot be marshalled without top-level mapping; nested exception is org.jibx.runtime.JiBXException: Supplied root object of class java.util.LinkedList cannot be marshalled without top-level mapping
Although I had all the marshalling beans set up I was passing in a collection instead of the object that JibX was expecting. For example:
Code:
ListOfUuids lou = new ListOfUuids () ; | |
lou.setList (export) ; | |
String xml = MarshallerUtils.convertObjectToXML (marshaller, export) ; |
Which should have been (see line 3):
Code:
ListOfUuids lou = new ListOfUuids () ; | |
lou.setList (export) ; | |
String xml = MarshallerUtils.convertObjectToXML (marshaller, lou) ; |
An easy mistake to make, but made more difficult to find by not knowing what the error message means!
3 comments
I am having a similar error and wanted to clarify something.
I am having a collection of Objects which I want to marshall/unmarshall.
I am getting the context for class :TimeRecord.class and marshalling that same Object and not the collection but it still gives me the same error :Supplied root object of class cannot be marshalled without top-level mapping.
My code:
IBindingFactory bfact =
BindingDirectory.getFactory(gov.irs.aec.bus.time_entry.entity.Time3081Record);
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.marshalDocument(time3081Rec, "UTF-8", null, new FileOutputStream(FILE_NAME));
Can you help me with this error?
If you give me your contact mail - I can send you my binding.xmls as well..
Please help!I didn't see ANY OTHER post than yours.
Do you have a test case of it not working?