Jibx Mapping:
<mapping class="com.sample.model.Account"
name="client-account"
flexible="true"
ordered="false">
<value name="test-account"
style="element"
name="client-account"
flexible="true"
ordered="false">
<value name="test-account"
style="element"
get-method="isTestAccount"
set-method="setTestAccount"
usage="optional"/>
<value name="status"
style="element"
get-method="getStatus"
set-method="setTestAccount"
usage="optional"/>
<value name="status"
style="element"
get-method="getStatus"
set-method="setStatus"
usage="optional" />
<value name="payment-type"
style="element"
get-method="getPaymentType"
set-method="setPaymentType"
usage="optional" />
<value name="payment-type"
style="element"
get-method="getPaymentType"
set-method="setPaymentType"
usage="optional" />
<value name="notes"
style="element"
get-method="getNotes"
set-method="setNotes"
usage="optional" />
</mapping>
style="element"
get-method="getNotes"
set-method="setNotes"
usage="optional" />
</mapping>
Marshalling Result :
test-account = false
<?xml version="1.0" encoding="UTF-8"?><client-account><status>Good</status><payment-type>Pre-Pay</payment-type><notes>unlimited</notes></client-account>test-account = true
<?xml version="1.0" encoding="UTF-8"?><client-account><test-account>true</test-account><status>Good</status><payment-type>Pre-Pay</payment-type><notes>unlimited</notes></client-account>Finally we found the answer from Dennis Sosnoski saying :(here)
When you set optional='true' on a primitive value, JiBX checks if the value is equal to the default and if so does not include the value when marshalling. If you'd like to have effectively a three-state representation - yes/no/not present - you can do so by using a Boolean value in place of the boolean. Alternatively, you can use a test-method to check if the value is present when marshalling.
It is worth knowing especially if you committed a change like this as "simple and easy " to your manager :-)
Update: We had another occurrence of this problem with a primitive integer. The field was optional so when the value is "0"(zero) jibx omits that element in the marshaled xml.Earlier we were thinking only about the 'boolean' types.