jaxb
  1. jaxb
  2. JAXB-57

JAXBElement to implement equals and hashCode

    Details

    • Type: Improvement Improvement
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0 EA1
    • Fix Version/s: not determined
    • Component/s: spec
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      57

      Description

      Hi.

      javax.xml.bind.JAXBElement currently does not override equals(...) and
      hashCode() methods. Since this class is used to wrap "real" values, it is
      desirable to implement these methods so that they take hashCode() and
      equals(...) of the wrapped value into an account.

      Basically, hashCode() and equals(...) should operate with name, declaredType,
      scope, nil AND value fields.

      I can implement these methods, but I need to know, where to find the jaxb-api
      project sources...

      Bye.
      /lexi

        Activity

        Hide
        Joe Fialli added a comment -

        Status for this request:

        Preference is for javax.xml.bind.JAXBElement and schema derived generated value
        classes to follow the same methodology for equals.

        Note that under certain circumstances, JAXB 2.0 RI is generating schema-derived
        value classes annotated with @XmlRootElement. Independent of whether a JAXB
        element is represented either as an instance of javax.xml.bind.JAXBElement or it
        is generated as a value class annotated with @XmlRootElement, the current status
        quo ensures both are using identity for equality comparisons.

        I would be fine with both JAXBElement and @XmlRootElement class using values for
        comparisons, but the feedback that I am receiving from RI team is they don't
        want to see the specification specify value based equality for schema-derived
        classes.

        Minimally, if JAXBElement.equals was to implement value equality, JAXB 2.0 would
        need to provide a customization to control whether schema-derived value classes
        had equality by value or by identity. Otherwise, the JAXB 2.0 specification is
        inconsistent by default and user has no ability to make it consistent:
        JAXBElement.equal being by value, schema-derived classes being by identity and
        only with a non-specified customization, does schema-derived value classes
        generate a value-based equals that is equivalent to JAXBElement.equal.

        Show
        Joe Fialli added a comment - Status for this request: Preference is for javax.xml.bind.JAXBElement and schema derived generated value classes to follow the same methodology for equals. Note that under certain circumstances, JAXB 2.0 RI is generating schema-derived value classes annotated with @XmlRootElement. Independent of whether a JAXB element is represented either as an instance of javax.xml.bind.JAXBElement or it is generated as a value class annotated with @XmlRootElement, the current status quo ensures both are using identity for equality comparisons. I would be fine with both JAXBElement and @XmlRootElement class using values for comparisons, but the feedback that I am receiving from RI team is they don't want to see the specification specify value based equality for schema-derived classes. Minimally, if JAXBElement.equals was to implement value equality, JAXB 2.0 would need to provide a customization to control whether schema-derived value classes had equality by value or by identity. Otherwise, the JAXB 2.0 specification is inconsistent by default and user has no ability to make it consistent: JAXBElement.equal being by value, schema-derived classes being by identity and only with a non-specified customization, does schema-derived value classes generate a value-based equals that is equivalent to JAXBElement.equal.
        Hide
        kohsuke added a comment -

        Moving it to the spec...

        Show
        kohsuke added a comment - Moving it to the spec...
        Hide
        kohsuke added a comment -

        Given that JAXB 2.0 is finalized without this, I think it's nearly impossible to
        add this in future JAXB releases at this point, since such a change would be
        likely to break compatibility.

        I guess for the purpose of the equals() plugin, the bean that refers to
        JAXBElement needs to take care of this.

        Show
        kohsuke added a comment - Given that JAXB 2.0 is finalized without this, I think it's nearly impossible to add this in future JAXB releases at this point, since such a change would be likely to break compatibility. I guess for the purpose of the equals() plugin, the bean that refers to JAXBElement needs to take care of this.
        Hide
        skaffman added a comment -

        This issue was rejected as WONTFIX 3 years ago, just as the 2.0 spec was being
        finalized. Now that the 2.2 spec is in EA, I think it's time to revisit the
        question, and have equals() and hashcode() get sensible definitions in JAXBElement.

        Show
        skaffman added a comment - This issue was rejected as WONTFIX 3 years ago, just as the 2.0 spec was being finalized. Now that the 2.2 spec is in EA, I think it's time to revisit the question, and have equals() and hashcode() get sensible definitions in JAXBElement.
        Hide
        lexi added a comment -

        +1 from me.

        I still think hashCode() and equals() must be defined for JAXBElement. However
        this can be also worked around using the hashCode and equals plugins from the
        JAXB2 Basics plugin package.

        http://confluence.highsource.org/display/J2B/Equals+plugin
        http://confluence.highsource.org/display/J2B/HashCode+plugin

        Show
        lexi added a comment - +1 from me. I still think hashCode() and equals() must be defined for JAXBElement. However this can be also worked around using the hashCode and equals plugins from the JAXB2 Basics plugin package. http://confluence.highsource.org/display/J2B/Equals+plugin http://confluence.highsource.org/display/J2B/HashCode+plugin

          People

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

            Dates

            • Created:
              Updated: