Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the fields used in hashcode and equals generation configurable #530

Conversation

SpaceBison
Copy link
Contributor

Added excludedFromEqualsAndHashCode option for specifying which properties should be excluded from equals() and hashCode() methods. It can be used both as an object-level array containing excluded property names or as a property-level boolean switch.

Example:

{
  "type": "object",
  "excludedFromEqualsAndHashCode" : [ "excludedByArray" ],
  "properties": {
    "notExcluded" : {
      "type" : "string"
    },
    "excludedByProperty" : {
      "type" : "string",
      "excludedFromEqualsAndHashCode" : true
    },
    "notExcludedByProperty" : {
      "type" : "string",
      "excludedFromEqualsAndHashCode" : false
    },
    "excludedByArray" : {
      "type" : "string"
    }
  }
}

notExcluded and notExcludedByProperty will be used while generating hashCode() and equals(), while excludedByProperty and excludedByArray won't.

I felt that excluding properties from the methods would be more fitting than listing the included ones (as discussed in issue #309), because that way the default behavior, which is including all properties in the methods, is modified rather than redefined.

@anuragpro
Copy link

Is this feature getting merged?

@SpaceBison
Copy link
Contributor Author

SpaceBison commented Sep 9, 2017

Took me long enough, but I updated this PR at last. Not sure why do the oraclejdk7 Travis tests fail with message: The JAVA_HOME environment variable is not defined correctly. Might this somehow be my fault?

@SpaceBison SpaceBison force-pushed the feature-excludefromhashcodeequals branch 2 times, most recently from ff0458e to cad88e6 Compare September 11, 2017 15:52
@joelittlejohn joelittlejohn added this to the 0.5.0 milestone Sep 11, 2017
@SpaceBison SpaceBison force-pushed the feature-excludefromhashcodeequals branch from 9631b64 to 4c17cfc Compare September 12, 2017 05:59
@SpaceBison SpaceBison force-pushed the feature-excludefromhashcodeequals branch from 4c17cfc to 1b7dec5 Compare September 12, 2017 06:14
@SpaceBison
Copy link
Contributor Author

Merged in 5eeb01e, now it builds. :)

@joelittlejohn
Copy link
Owner

Yeah. It looks like Travis changed their base image and broke installing of Oracle JDKs.

@joelittlejohn joelittlejohn merged commit 8b8806d into joelittlejohn:master Sep 12, 2017
@joelittlejohn joelittlejohn changed the title #309 - Make the fields used in hashcode and equals generation configurable Make the fields used in hashcode and equals generation configurable Sep 20, 2017
wigbam pushed a commit to wigbam/jsonschema2pojo that referenced this pull request Nov 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants