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 #309

Closed
d4rxh4wx opened this issue Mar 13, 2015 · 10 comments
Closed

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

d4rxh4wx opened this issue Mar 13, 2015 · 10 comments

Comments

@d4rxh4wx
Copy link

#241 (comment)

@ltoinel
Copy link

ltoinel commented Mar 13, 2015

+1

@joelittlejohn
Copy link
Owner

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?

@d4rxh4wx
Copy link
Author

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.

@joelittlejohn
Copy link
Owner

@d4rxh4wx do you mean in the object itself? like:

{
  "type" : "object",
  "javaHashcodeEqualsFields" : ["foo","bar"]
}

@d4rxh4wx
Copy link
Author

Yes. That sounds good.

@MikaelElkiaer
Copy link

+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)

@skarian92
Copy link

Hi
So any updates on the problem.How can I configure HashcodeEqualFields??

@joelittlejohn joelittlejohn changed the title Making the fields to use in the hashcode and equals generation configurable Make the fields used in hashcode and equals generation configurable Aug 4, 2015
@rozhok
Copy link

rozhok commented Dec 25, 2015

+1
Also I don't like to include dependency to commons-lang and want to see plain java8 equals/hashCode like

@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);
}

SpaceBison added a commit to SpaceBison/jsonschema2pojo that referenced this issue Mar 14, 2016
SpaceBison added a commit to SpaceBison/jsonschema2pojo that referenced this issue Mar 14, 2016
SpaceBison added a commit to SpaceBison/jsonschema2pojo that referenced this issue Mar 14, 2016
@szhem
Copy link

szhem commented May 11, 2017

+1

I'd like hashcode, equals and toString with java8 style too

SpaceBison added a commit to SpaceBison/jsonschema2pojo that referenced this issue Sep 11, 2017
SpaceBison added a commit to SpaceBison/jsonschema2pojo that referenced this issue Sep 12, 2017
SpaceBison added a commit to SpaceBison/jsonschema2pojo that referenced this issue Sep 12, 2017
@joelittlejohn
Copy link
Owner

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 excludedFromEqualsAndHashCode schema extension).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants