jaxb
  1. jaxb
  2. JAXB-555

boolean with default breaks Java Bean introspection

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8
    • Fix Version/s: not determined
    • Component/s: xjc
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      555

      Description

      Hello, recently I began using JAXB generated classes in combination with Apache
      Commons BeanUtils (like Struts), took me several hours of debugging why a
      boolean property could be read, but could not be written to.

      In an XML Schema the following attribute declaration on an element:

      <xs:attribute name="repeat" type="xs:boolean" default="false"/>

      XJC generates the following getter/setter methods:

      public boolean isRepeat() {
      if (repeat == null)

      { return false; }

      else

      { return repeat; }

      }

      public void setRepeat(Boolean value)

      { this.repeat = value; }

      Notice how the getter is type 'boolean' and the setter is type
      'java.lang.Boolean', this breaks BeanUtils (it will treat the property as
      read-only), and I believe it generally breaks the Java Bean specification
      contract (getter type must match setter argument type).

      As for working around the bug, within the build script, I pass the XML Schema
      through the following XSLT before running the JAXB compiler (JAX-WS wsimport Ant
      Task actually):

      <xsl:stylesheet xmlns="urn:HVODWebServiceTypes"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
      <xsl:template match="@default[../@type='xs:boolean']"/>

      <xsl:template match="node()|@*">
      <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
      </xsl:template>
      </xsl:stylesheet>

      However the issue isn't over with yet, now I have run into JAXB-131. Hopefully
      I can use external bindings customization to change java.lang.Boolean isRepeat
      into getRepeat.

        Activity

        Hide
        Pavel Bucek added a comment -

        already fixed in 2.1.9

        Show
        Pavel Bucek added a comment - already fixed in 2.1.9
        Hide
        Pavel Bucek added a comment -
            • Issue 511 has been marked as a duplicate of this issue. ***
        Show
        Pavel Bucek added a comment - Issue 511 has been marked as a duplicate of this issue. ***
        Hide
        Martin Grebac added a comment -
            • Issue 631 has been marked as a duplicate of this issue. ***
        Show
        Martin Grebac added a comment - Issue 631 has been marked as a duplicate of this issue. ***

          People

          • Assignee:
            jaxb-issues
            Reporter:
            gturner
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: