I am trying to exclude some fields for a subclass during the hashcode generation, and it seems that either I have the option to exclude it entirely or none, but not the specific fields even after specifying it in the exclusion list
For e.g. if I have a
Class Car {
@HashCodeExclude
int id
int modelYear
String color
TyreClass tyre;
}
Class TyreClass {
@HashCodeExclude
int id;
@HashCodeExclude
int version;
float radius
String colour
double width
}
Now when I try to invoke the method HashCodeBuilder.reflectionHashCode, like:
TyreClass tyreObject = new TyreClass();
type object.setId(1);
Car carObject_1 = new Car();
carObject_1.setId(1);
carObject_1.setTyre(tyreObject);
Car carObject_2 = new Car();
carObject_2.setVersion(2); /// Changing this value which is to be excluded for hashcode generation
carObject_2.setTyre(tyreObject);
List<String> excludedFields = new ArrayList<>();
excludedFields.add("id");
excludedFields.add("version");
int hashCode_1 = HashCodeBuilder.reflectionHashCode(carObject_1, excludedFields)
int hashCode_2 = HashCodeBuilder.reflectionHashCode(carObject_2, excludedFields)
Since I have excluded the field version
by adding it to the exclusion list, I was hoping that it would be excluded but it's not.
Can somebody guide me on what I can do to exclude the version
field of the Tyre object?