I have class where I inheritage some fields, among them my id fields and those I difference on for the object. I am using lombok to generate my @EqualsAndHashCode and @ToString, but only want to use my super class's version, and exclude all fields in my class. I am wondering if there is a way to do that, without using the exclude and then add all fields.
My classes:
@EqualsAndHashCode(of = { "id" })
@ToString(of = { "id", "email", "name" })
@Data
public abstract class Resource {
@Id
private Integer id;
private String name;
private String email;
}
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Data
public class Employee extends Resource {
private Organisation organisation;
private List<Skill> skills = new ArrayList<Skill>();
}
Here I will get organisation and skills in my ToString, Equals and HashCode.
To exclude them I can use:
@ToString(callSuper = true, exclude = { "organisation", "skills" })
However as I have more fields than the example, and there might come more in the future, I would prefer if I could exclude all except for the ones from my super class.
I can also add one field in with the of = {}.
Is there any better way to accomplish that?