After my long winded explaination I figured it out. I just have to call unmarshal.setClass(WalletFlexFacade.class) to make it unmarshal to that Class.
Craig. On Tue, Jan 4, 2011 at 6:52 PM, Craig Tataryn <[email protected]> wrote: > Running into a problem with Castor I'm hoping there is a solution for. I'm > currently running v1.3.1 and have the following mapping: > > > <class name="com.some.domain.Wallet"> > <map-to xml="Wallet" /> > <!-- Bunch of properties --> > </class> > > <!-- > Wallet that has special properties used to facilitate marshalling > which is not easily achieved using just the plain Domain objects > --> > <class name="com.some.domain.WalletFlexFacade" > extends="com.some.domain.Wallet"> > <map-to xml="Wallet" /> > <field name="expenseRequests" collection="collection" > type="com.some.domain.flex.ExpenseRequestFlexFacade"> > <bind-xml name="ErLine" /> > </field> > </class> > > I then unmarshal some XML that has the <ErLine> elements in them like so: > > String _MAPPING = > XMLMapper.class.getResource("/resources/mapping/DomainObjectsMapping.xml").toExternalForm(); > Mapping _MAP = new Mapping(); > _MAP.loadMapping(_MAPPING); > > InputSource xmlSource = new InputSource(new StringReader(xml)); > Unmarshaller unmarshal = new Unmarshaller(_MAP); > unmarshal.setValidation(false); > Object object = unmarshal.unmarshal(xmlSource); > > In the log I get this: > > DEBUG - Get descriptor for: com.some.domain.ErLine found: null > DEBUG - Now in method: org.exolab.castor.xml.util.resolvers.ByIntrospection > resolving: com.some.domain.ErLine > DEBUG - Ignored problem at loading class: com.some.domain.ErLine through > class loader: sun.misc.launcher$appclassloa...@601bb1, exception: > java.lang.ClassNotFoundException: com.some.domain.ErLine > DEBUG - Called addAllDescriptors with null or empty descriptor map > DEBUG - Get descriptor for: com.some.domain.ErLine found: null > DEBUG - Adding class name to missing classes: com.some.domain.ErLine > DEBUG - unable to find FieldDescriptor for 'ErLine' in ClassDescriptor of > Wallet - ignoring extra element. > DEBUG - unable to find FieldDescriptor for 'ErLine' in ClassDescriptor of > Wallet - ignoring extra element. > DEBUG - unable to find FieldDescriptor for 'ErLine' in ClassDescriptor of > Wallet - ignoring extra element. > > Ok, I think to myself, for some reason Castor can't work backwards from the > <bind-xml> statement for the ErLine element to realize that <ErLine> really > maps to ExpenseRequestFlexFacade (and the get/setExpenseRequestFacade) when > unmarshalling... Also, the "object" being returned from > unmarshal.unmarshal(..) ends up being is a Wallet, not a > WalletFlexFacade!!!! So what I do is add "setErLine/getErLine" methods to > WalletFlexFacade and change the <field> name attribute in the mapping from > "expenseRequests" to "erLines" in hopes that Castor will notice that > WalletFlexFacade is the right class to instantiate, not Wallet. Nope, that > didn't work. It's just hell bent on using "Wallet". > > So my question here is: How do I get it to use a WalletFlexFacade and not > the parent class (Wallet) when unmarshaling? > > Thanks, > > Craig. > > -- > Craig Tataryn > site: http://www.basementcoders.com/ > podcast:http://feeds.feedburner.com/TheBasementCoders > irc: ThaDon on freenode #basementcoders, ##wicket, #papernapkin > twitter: craiger > -- Craig Tataryn site: http://www.basementcoders.com/ podcast:http://feeds.feedburner.com/TheBasementCoders irc: ThaDon on freenode #basementcoders, ##wicket, #papernapkin twitter: craiger

