2

I have a class with a complex method which returns boolean (no property field or setter for this field provided). I need to bind this class with JiBX so result of the method would be marshalled to XML element/attribute and would be omitted when unmarshalling. So I want to get something like this:

<mapping name="freak" class="com.test.Freak">
    <namespace uri="http://www.test.com/schemas/test" default="elements" />
    <value name="id" field="id" style="attribute"/>
    <value name="real-freak" get-method="isRealFreak" style="attribute" usage="optional" />        
</mapping>

P.S. I can't fix this class to add stub setter, need to use it as is.

andrey
  • 135
  • 1
  • 8

1 Answers1

5

Because a boolean (a primitive) will always have a value, this will not be possible, unless you switch to Boolean (which allows a null).

Your only solution can be having an output-only binding:

<binding ... direction="output">

This will ensure that the binding is one way, which I'm guessing you are fine with since you have no mechanism to set that value with anyways. If you need both directions and you can't modify your class, you will need to extend your class and use a Boolean and use a separate input-only binding.

aweigold
  • 6,532
  • 2
  • 32
  • 46