commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <>
Subject Re: [betwixt] some problems with 0.6
Date Wed, 06 Jul 2005 19:01:58 GMT
On Wed, 2005-07-06 at 15:23 +0200, Wolfgang=?ISO-8859-1?Q?H=E4felinger?=
> Hello,
> I just started to use betwixt for reading XML into JavaBeans (is that 
> called de-serialization?).
> I'm using version 0.6 which appears to be a bit outdated. 


i'd strongly recommend upgrading to the latest release candidate. it's
been pretty well tested now and i expect it to be release within the
next week. it's a feature release and there's quite a lot of new stuff
in there.

> Nevertheless I 
> would like to give
> some comments:
> Simply mapping XML elements into JavaBeans works impressivley well. In 
> fact I really had
> trouble to understand the code I need to analyze because everthing appears 
> to happen 
> "automagically".

that's the blessing and the curse...

> My problem starts when doing something "not straightforward". It's 
> probably quite simple
> for the experts I guess. 

not necessarily

> All I want to have is a mapping between 
> <project>
>   <dependency alias="LOG4j">
>     <version>1.2.8<version>
>   <dependency />
>  </project> 
> and this Bean:
> class Dependency {
>   ..
>   void setAlias(String s) { .. }
>   void setVersion(String s) { .. }
> };
> In other words, the attribute 'alias' shall be mapped to 'setter' 
> setAlias(). 
> I assume that I need to create a file "Dependency.betwixt" - the 
> documentation does not
> really explain this very well.  

that's on way to do it, certainly. documentation is a difficult for mot
open source projects and patches would be gratefully received. (creating
improving documentation is probably the best way to)

> For  example,  the tutorial in [1] just 
> mentions a ".betwixt"
> file but will it  be a  "Channel.betwixt"  or  a  "RSS.betwixt"?? Note 
> also  that  there's  no
> ".betwixt" file (whatsoever) in the tutorial's source code directory [2] 
> (!).

the problem is that it's a link to the javadocs which don't include
those files. the example code is in the source distribution.

it would be much better to have a good way to make available an example.
i think maven may now have an example plugin (but i'm not sure of it's
quality). suggestions about the better ways to distribution example code
would be gratefully received.

> Let's assume now that "Dependency.betwixt" is ok. What should be in this 
> file??
> => A plain empty file creates an Exception. Why? Wouldn't it be better to 
> apply to have 
>     a standard mapping this case?  There's  not  a  big difference between 
> an empty file
>     and a non-existing file (at least not for me).

probably so (or at least a better message). should be easy to patch
this. any volunteers?

> => I'm getting similar exceptions in this cases:
>     a. only <xml> header
>     b. <info/>
> => I would have expected a kind of warning in this case:
>     <?xml version="1.0" encoding="UTF-8" ?>
>     <info>
>       <element name="non-existing-element">
>         <addDefaults/>
>       </element> 
>     </info>

betwixt does not know the schema of the xml (indeed, it does not require
the xml to have a schema). above is an absolutely legitimate document
mapping the object graph for the bean to xml fragments wrapped by an
element called 'non-existing-element'.

> Another thing which is not entirly clear is what should be the 'root' 
> element for Dependency.betwixt?
> Should it  be:
>     <?xml version="1.0" encoding="UTF-8" ?>
>     <info>
>       <element name="project">
>          [..]
>       </element> 
>     </info>
> or should it be
>     <?xml version="1.0" encoding="UTF-8" ?>
>     <info>
>       <element name="dependency">
>          [..]
>       </element> 
>     </info>
> When looking at the tutorial [1] the latter seems to be the case (and this 
> appears to be "logical") but
> it's not well explained.

the problem is that either may be correct (which is probably why it's
hard to explain :)

the dot betwixt file describes a mapping between the xml graph and the
object graph: it describes how elements and attributes relate
properties. it's most usually to have a strong correspondence but
betwixt is flexible enough not to require this. it also allows (some)
structural differences between the two graphs.

given effort, either way would work but i'd suggest starting with the
simplest case which is mapping the entire document. For the full
document, i think you'll find something like:

<?xml version="1.0" encoding="UTF-8" ?>
  <element name='project'>
    <element name='dependency'>
      <attribute name='alias' property='alias'/>
      <element name='version property='version'/>

will work. there are easy and less verbose way to perform this mapping
with betwixt but i think a full dot betwixt file is a good illustration.

if you continue to have difficulties understanding the tutorial, there
are a number of books and a few articles that may off better
introductions that the one on site. alternatively, download the source
and take a look a the test and example code. or ask more questions on
the list.

(it would be good to have some tools for creating these betwixt files
which would help with stuff like this...)

- robert

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

View raw message