-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #309
Comments
+1 |
Hi all, how would you propose configuring this? Would you like to add a field to each property, have a global configuration value containing a list of field names, or do something like include only 'required' fields? |
Hi. I would go with a list of field names. In that way, you can see in one place which fields are participating to equals and hashcode. |
@d4rxh4wx do you mean in the object itself? like: {
"type" : "object",
"javaHashcodeEqualsFields" : ["foo","bar"]
} |
Yes. That sounds good. |
+1 How about an option for using super classes' fields for equals and hashCode? Edit: Another option could be to completely leave out equals and hashCode if a class extends another class. (At least this is viable in my case, as I have a unique identifier field in my super-class) |
Hi |
+1 @Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Message that = (Message) o;
return Objects.equals(type, that.type) &&
Arrays.equals(updated, that.updated) &&
Arrays.equals(deleted, that.deleted) &&
Objects.equals(content, that.content);
}
@Override
public int hashCode() {
return Objects.hash(type, updated, deleted, content);
} |
…ation configurable
…ation configurable
…ation configurable
+1 I'd like hashcode, equals and toString with java8 style too |
…ation configurable
…ation configurable
…ation configurable
We now have equals, hashCode and toString methods that do not depend on commons-lang, and we also allow fields to be excluded from these (see |
#241 (comment)
The text was updated successfully, but these errors were encountered: