public static boolean presenceDeserializer(String value) { return true; }
and set up the binding to use this deserializer method for the <required/> element, binding the element to feature1Required. If the <required/> element is present the deserializer will get called; if the element isn't present the boolean will just have the default "false" value. You could also do something similar for the <feature1> element - say that it contains a <value type="text" .../> which you bind to the feature1Supported flag, using the same presenceDeserializer.
This gets more complicated if you need to marshal as well as unmarshal. In theory you should be able to do this with test-methods for the values, but it might get messy. This would also mean more changes to your code, while for unmarshalling you can do essentially everything in the binding definition.
I suppose for 2.0 I could generalize the test-method to also support a test-field, or just define some way of associating an element directly with a boolean. That gets ugly, though, in that you want it both for simple elements (corresponding to <value> elements in the binding definition) and those with substructure (corresponding to <structure> elements). I think this has come up a few times, though, so some easier way of handling the situation would be nice.
- Dennis
Mocky Habeeb wrote:
I don't believe there is a better way to do that than with your own marshaller since you're not directly mapping a value in the xml to your java. I think the custom marshaller is the way to go, it seems like you want to extend what JiBX can do.
Mocky
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Chen Sent: Saturday, April 16, 2005 3:28 AM To: jibx-users@lists.sourceforge.net Subject: [jibx-users] Binding File question
Hi,
I am wondering if anyone can tell me if it's possible to map the following XML to a class:
The XML is something like this:
<features> <feature1> <required/> </feature1> </features>
The class is something like this:
class Features { boolean feature1Supported; boolean feature1Required;
//additional set/get methods }
Is it possible with JiBX to define the binding file such that I can set a boolean value when a certain element exists (ie. <required/> in this case)? If so, how do I go about handling subelements and mapping them to the Features class as shown above? I've been pondering this for a while. The only way I can currently deal with this is through custom marshallers and unmarshallers.
I am wondering if there is a better way other than writing custom code.
Thank you for your time,
Chris
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users