Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with use Castor from Spring OXM.

 
Vladimir Koba
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vladimir Koba
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply!
 
Joseph Mokenela
Ranch Hand
Posts: 66
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also if you are using introspection auto-complete is spelled wrong
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic