aspose file tools*
The moose likes Spring and the fly likes Problem with use Castor from Spring OXM. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Problem with use Castor from Spring OXM." Watch "Problem with use Castor from Spring OXM." New topic
Author

Problem with use Castor from Spring OXM.

Vladimir Koba
Greenhorn

Joined: May 29, 2012
Posts: 4
Hi all! I had a problem with unmarshalling xml. More details:

I've a XML file:


Also, I've Contractor pojo.


So, I use Castor for unmarshall xml.

Castor mapping file:


Spring configuration:


Finally, I get list of contractor:


After run, I've follow error:
Caused by: org.xml.sax.SAXException: unable to find FieldDescriptor for 'contractor' in ClassDescriptor of contractors
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:2020)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1436)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
... 9 more

Can I get list of Contractor without wrapper object? Please, help!
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

This post might get a better response in the XML forums. From what I have done with Castor I have not found an answer to this riddle that I am satisfied with. If you are concerned primarily with unmarshaling you can skip using springs unmarshaller and use Castors directly. Their unmarshaller allows you to pass in an object. You can do something similar to



This process instructs the Unmarshaller to expect an ArrayList as the
root element, and it will use the mapping file for classes contained
inside the ArrayList.

Personally I think this ends up being more of a hack than just creating the wrapper object and being done with it though.

Also on a side note I would avoid doing things like this:



You may have been doing that just for illustration but just in case you were not, it defeats the purpose of dependency injection. This should be wired in from your bean configuration or via annotations like @Autowired etc.


[How To Ask Questions][Read before you PM me]
Vladimir Koba
Greenhorn

Joined: May 29, 2012
Posts: 4
Thanks for reply!
Joseph Mokenela
Ranch Hand

Joined: Jan 18, 2011
Posts: 59

You have somehow missed something in the castor mapping file. Change line 4 to and add another class element in the castor mapping that will map to contractors tag.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Also if you are using introspection auto-complete is spelled wrong
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with use Castor from Spring OXM.
 
Similar Threads
Castor Help with unmarshalling
How to map arraylist containing a list of hashmaps using castor
[Castor] "unmarshalling exception: unable to find FieldDescriptor for"
Problem in castor please help
Caused by: java.lang.InstantiationException