JiBX
  1. JiBX
  2. JIBX-308

problem with usage=optional and a specified format

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: JiBX 1.2.1
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      Redhat, JBoss 4.2.2
    • Number of attachments :
      0

      Description

      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.

        Activity

        Hide
        Dennis Sosnoski added a comment -

        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.

        Show
        Dennis Sosnoski added a comment - 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.
        Dennis Sosnoski made changes -
        Field Original Value New Value
        Assignee Dennis Sosnoski [ dsosnoski ]
        Resolution Not A Bug [ 6 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Dennis Sosnoski made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Todd Gould
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: