JiBX binding value for getter only

I have a class with a complex method that returns a boolean (no property field or setter for that field). I need to bind this class to JiBX so the result of the method will be bound to the XML element / attribute and will 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>

      

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

+2


source to share


1 answer


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

Your only solution might be pin-only:



<binding ... direction="output">

      

This ensures that the binding is one way, and I am assuming that you are fine as you have no mechanism to set this value anyway. If you want both directions and you cannot change your class, you will need to extend your class and use boolean and use a separate input-only binding.

+5


source







All Articles