patrodyne / hisrc-basicjaxb

XJC plugins and tools for JAXB.
BSD 3-Clause "New" or "Revised" License
16 stars 6 forks source link

Exclude properties from hashCode #7

Closed theseeker58 closed 1 year ago

theseeker58 commented 1 year ago

First, great job mate! Not quite an issue. A nice-to-have instead. It'd be pretty useful to exclude properties from hashCode and/or equals method generation, using annotations in xjb or xsd. Thank you!

patrodyne commented 1 year ago

Thanks. Take a look at basicjaxb/higher/tests/ignoring

theseeker58 commented 1 year ago

Thank for your answer. I'm using global.xjb customizations since I don't want to tamper with the external ISO XML 20022 xsd schema. I couldn't understand how to ignore a field. For example using Jackson I can ignore a property this way

        <jaxb:bindings node="//xsd:complexType[@name='MessageHeaderType']//xsd:element[@name='CtrlSum']">
            <annox:annotate target="field">@com.fasterxml.jackson.annotation.JsonIgnore</annox:annotate>
        </jaxb:bindings>

How can I prevent the plugin from calculating hashcode using that field? Using just <arg>-XhashCode</arg> in pom generates a method that use all properties

theseeker58 commented 1 year ago

Ok, gotcha! No need to use annox. In the above example this works

<jaxb:bindings node="//xsd:complexType[@name='MessageHeaderType']//xsd:element[@name='CtrlSum']">
    <hashCode:ignored/>
</jaxb:bindings>

And of course adding this

               xmlns:hashCode="http://jvnet.org/basicjaxb/xjc/hashCode"
               jaxb:extensionBindingPrefixes="hashCode"

Thank you again!