jaxb
  1. jaxb
  2. JAXB-325

Different types for generated getters and setters

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.2
    • Fix Version/s: not determined
    • Component/s: xjc
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      325

      Description

      See forum posting at http://forums.java.net/jive/thread.jspa?messageID=204042
      for a description of the problem.

      Sample bindings file:

      <jxb:bindings version="1.0"
      xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
      xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
      xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <jxb:bindings schemaLocation="test.xsd" node="/xs:schema">
      <jxb:globalBindings optionalProperty="wrapper">
      <jxb:javaType name="java.lang.Float" xmlType="xs:float"/>
      </jxb:globalBindings>
      </jxb:bindings>
      </jxb:bindings>

      Sample XML schema:

      <?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns="urn:test"
      targetNamespace="urn:test"
      elementFormDefault="qualified" attributeFormDefault="unqualified">

      <xsd:complexType name="MyTestType">
      <xsd:attribute name="floatAttribute" type="xsd:float" default="1.0"/>
      </xsd:complexType>

      </xsd:schema>

      Generated method on MyTestType class is:

      public float getFloatAttribute() {
      if (floatAttribute == null)

      { return new Adapter1().unmarshal("1.0"); }

      else

      { return floatAttribute; }

      }

      When the attribute has a default value, neither the global type mapping
      xsd:float<->java.lang.Float nor the optionalProperty="wrapper" setting will
      result in the method return type being set to java.lang.Float.

      The use case is to introspect the generated classes as Java beans. The different
      types on the getter and setter make this impossible.

        Activity

        Hide
        kohsuke added a comment -

        See
        http://www.nabble.com/JAXB%2C-Introspector%2C-BeanInfo-and-method-sigantures-tf1632437.html

        Changing to RFE as this behavior is not in violation of the spec.

        Show
        kohsuke added a comment - See http://www.nabble.com/JAXB%2C-Introspector%2C-BeanInfo-and-method-sigantures-tf1632437.html Changing to RFE as this behavior is not in violation of the spec.
        Hide
        dean_jones added a comment -

        Created an attachment (id=168)
        Patch for bug

        Show
        dean_jones added a comment - Created an attachment (id=168) Patch for bug
        Hide
        dean_jones added a comment -

        In the interests of getting this bug fixed, I've attached a patch.

        Incidentally, I was surprised to see this bug re-classified from defect to RFE.
        I might be missing something, but the observed behaviour seems to violate the
        spec, specifically sec 7.9.1.1: "The javaType, if specified, is the Java
        datatype to which xmlType is to be bound." [on reading the spec, the
        'optionalProperty' setting seems to be a red herring as this is only for use
        with optional elements/attributes, and I don't suppose an attribute with a
        default value counts as optional.]

        Now, sec 7.9.1.1 could, I suppose, be referring to the type of the generated
        field, rather than the correponding getter, but that would be odd since the type
        of the field is pretty much irrelevant - it's the type returned/accepted by the
        corresponding getter/setter that clients of the generated classes use, and which
        is therefore important.

        Show
        dean_jones added a comment - In the interests of getting this bug fixed, I've attached a patch. Incidentally, I was surprised to see this bug re-classified from defect to RFE. I might be missing something, but the observed behaviour seems to violate the spec, specifically sec 7.9.1.1: "The javaType, if specified, is the Java datatype to which xmlType is to be bound." [on reading the spec, the 'optionalProperty' setting seems to be a red herring as this is only for use with optional elements/attributes, and I don't suppose an attribute with a default value counts as optional.] Now, sec 7.9.1.1 could, I suppose, be referring to the type of the generated field, rather than the correponding getter, but that would be odd since the type of the field is pretty much irrelevant - it's the type returned/accepted by the corresponding getter/setter that clients of the generated classes use, and which is therefore important.

          People

          • Assignee:
            Martin Grebac
            Reporter:
            dean_jones
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: