Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

[castor-user] How to marshall null fields and empty collections to empty elements

Alessandro

2012-02-07

Replies: Find Java Web Hosting

Author LoginPost Reply
Hello everybody,

I started using Castor a few weeks ago, quite happily until now. But I
came across an issue I haven't found a solution for.

I want to generate an XML with empty tags where no value is present in
my java object. Be that an empty collection or a null field. With the
default configuration though I don't get any element at all.

How can I instruct castor to do this?

Here is a fragment of my castor-mapping.xml

<class name="org.youthnet.doit.syndication.common.model.response.SyndicationOpportunity">
 <map-to xml="opportunity"
ns-uri="http://www.do-it.org.uk/volunteering-opportunity"/>
 <field name="title" type="java.lang.String"/>
 <field name="summary" type="java.lang.String"/>
 <field name="availability"
type="org.youthnet.doit.syndication.common.model.response.SyndicationAvailability">
   <bind-xml name="times"/>
 </field>
 <field name="activities" collection="arraylist"
type="org.youthnet.doit.domain.Activity">
   <bind-xml location="activities" name="activity"/>
 </field>

..... for instance I want an <activities> tag even if the activities
collection is empty.

Any clue about how to do this?
--
Alessandro

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 junlu.com - Jax Systems, LLC, U.S.A.