jaxb
  1. jaxb
  2. JAXB-913

XmlAdapter<String, Boolean> should be able to apply to small-b boolean (primitive) bean fields as well as Boolean fields

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.1
    • Fix Version/s: None
    • Component/s: runtime
    • Labels:
      None

      Description

      Registering an XmlAdapter<String, Boolean> with the Unmarshaller and marking the bean field with an @XmlJavaTypeAdapter annotation results in the error message:

      ...is not applicable to the field type boolean.

      Here's someone else with a similar request:
      http://stackoverflow.com/questions/6552740/jaxb-suppress-boolean-attribute-if-false

      My use case is that although I'm happy for marshalling to convert a boolean to the string "true" or "false" for output in XML, I'd like more flexibility in the unmarshalling. Ideally "true" and "TRUE" would unmarshal successfully to boolean = true.
      I'm using Jaxb for a simple unmarshalling task of XML to a bean and am not providing a schema or a binding customisation file. For the record, even for the big-B Boolean case it would be great to be able to register default behaviour for booleans without having to tag the bean field with @XmlJavaTypeAdapter. There seems to be no facility to programatically override this default behaviour at the Unmarshaller level.

      I could choose to transform the TRUE into a true as part of a preprocessing step. However, I only want to apply that preprocessing logic when the value is definitely going to be attached to a boolean or Boolean. Because I don't have a schema, any preprocessor would have to change all instances of "TRUE", even if they are destined to be a String and would be far better staying as "TRUE".

        Activity

        Hide
        javaprog added a comment - - edited

        Another user with the same issue: http://stackoverflow.com/questions/14053063/marshaling-a-long-primitive-type-using-jaxb

        Also affects version 2.2.7.

        Show
        javaprog added a comment - - edited Another user with the same issue: http://stackoverflow.com/questions/14053063/marshaling-a-long-primitive-type-using-jaxb Also affects version 2.2.7.

          People

          • Assignee:
            Martin Grebac
            Reporter:
            daveboden
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: