The behavior you describe is how optional is defined to work when marshalling - if the value is the default ("false", in the case of a boolean), it is not generated in the output. To get the behavior you want, you'd need to have a separate flag to indicate the presence or absence of the element. You can use the test-method and flag-method attributes (part of the property group: http://jibx.sourceforge.net/binding/binding-attributes.html#property) to work with this added flag in the binding.
- Dennis Dennis M. Sosnoski XML and Web Services in Java Training and Consulting http://www.sosnoski.com - http://www.sosnoski.co.nz Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117 jibx-us...@abilsoft.com wrote: > Hello: > > I have a document that requires serialization of boolean values > in a 'yes' and 'no' format. I have defined a format in my > binding.xml as follows to accomplish this trivial conversion: > > > <format type="boolean" label="yesNoBoolean" > serializer="ConversionUtils.serializeYesNoBoolean" > deserializer="ConversionUtils.deserializeYesNoBoolean"/> > > I then reference the format in my mapping as follows: > > <value style="element" name="isGateway" > get-method="isGateway" set-method="setGateway" > format="yesNoBoolean" usage="optional"/> > > When I test a test-case input document via the JiBX roundtrip or > my own JUnit test case this works just fine if (and only if) the > underlying boolean is true. As soon as I test with a false > value, the serialization process no longer creates the associated > element. I presume that this may be some sort of optimization on > part of the usage=?optional? attribute attempting to optimize the > output or something? However, this causes the roundtrip to fail > as well as my JUnit test case which are both expecting to see the > attribute with a specified value. > > I have debuged the yesNoBoolean serializer and deserializers and > have therefore verified that the serializers are never called > when the underlying value is false (only when true) and that they > are performing as would be expected otherwise and without failure. > > I also tried specifying a default=?no? on the format. While this > did not produce any errors in and of itself, it also did not fix > the roundtrip or JUnit test case failures. > > Finally, and most telling, if I remove the usage=?optional? from > the value statement in the mapping, all works fine and as > expected. However, this is not what I need, as this element > value is truly optional. > > Is this a known feature/bug relative to the combination of format > and optional values? Am I missing something else? Is there a > way to achieve the truly optional behavior for the value, while > using the yeNoBoolean format. > > TIA! > > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables unlimited > royalty-free distribution of the report engine for externally facing > server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jibx-users > > ------------------------------------------------------------------------------ Are you an open source citizen? Join us for the Open Source Bridge conference! Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250. Need another reason to go? 24-hour hacker lounge. Register today! http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users