commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Gladwell <>
Subject Re: [betwixt] Making deserialise work like serialise (long)
Date Thu, 14 Jul 2005 16:46:55 GMT
robert burrell donkin wrote:
> On Tue, 2005-07-12 at 15:47 +0100, Ricardo Gladwell wrote:
>> Hi All,
> hi Ricardo
>> How can I simulate this behaviour for serialisation? That is, how do I
>> force betwixt to interpret the bank account and generate an appropriate
>> country specific bank account, placing it into the bank account property
>> of the shopper, without having to create an additional bean for generic
>> bank account to hold the country-specific bank account.
> i suggest that you being by getting hold of the betwixt source (either
> from subversion see or from
> the latest release candidate
> you need to create
> a custom ChainedBeanCreator which creates the right bean based on the
> element type (take a look at ChainedBeanCreatorFactory for example of
> creating a bean on the basis of an attribute value) and then add it to
> the chain used to create new beans (see
> 20Beans%20-%20In%20Depth). though you'll have to add an entry for each
> subclass, it should work.

Thanks for the above. Unfortunately, the dependencies for the project 
I'm working on are quite strict and it wouldn't be possible to use 
snapshot code as you suggest above (it is worth noting the Maven 
repository on Ibiblio for this project is out of date, snapshots and 
all). Otherwise, implementing your own ChainedBeanCreator and modifying 
the bean creator chain is a very good idea.

In the end, I cheated and hard-coded XPath to read specific bank 
accounts using the BeanReader.registerBeanClass method:


And reading the file twice: once for the XML file, and again to extract 
bank details and "manually" insert them into the appropriate bean. That 
said, the bank accounts do not seem to be being read properly and the 
parse() method returns null. Not sure what might be causing this.

> BTW any ideas about the best way to solve (or at least, chip away at)
> the general problem would be gratefully received

Not sure this problems is resolvable: it means creating a reverse of the 
betwixt file and applying it intelligently to XML reading. For example, 
the following betwixt file:

<!-- AustrianBankAccount.betwixt -->
<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="element">
   <element name="bankAccount">
     <element name="bankAccount-AT">...

Would have to be interpreted as being /bankAccount[bankAccount-AT] -> 
AustrianBankAccount. How would BeanReader be able to grasp this is what 
is wanted from the above than, for example, the bankAccount-AT refers to 
a property of the AustrianBankAccount bean, for example? Some sort of 
intelligent comparison between the betwixt file and the bean object 
model would be required to interpolate expected behaviour. Perhaps some 
sort of additional scripting would be required?

Kind regards...

-- Ricardo Gladwell

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message