Lets say this is my class. And I want getters and setters for all fields except the Date. Is the a way to exclude?
@Data
public class User {
String first;
String last;
String email;
Date dob;
Boolean active;
}
I think this is the only way to hide:
@Getter(value=AccessLevel.PRIVATE)
@Setter(value=AccessLevel.PRIVATE)
private Date dob;
or maybe better with AccessLevel.NONE
like Ken Chan's answer suggests
so overriding the access level. However this does not hide it from constructors.
Also you can make tricks with inheritance. Define class like:
public class Base {
// @Getter if you want
private Date dob;
}
and let your User
to extend that:
@Data
public class User extends Base {
private String first;
private String last;
private String email;
private Boolean active;
}
Well , or better yet use AccessLevel.NONE
to completely make it does not generate getter or setter. No private getter or setter will be generated.
@Getter(value=AccessLevel.NONE)
@Setter(value=AccessLevel.NONE)
private Date dob;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With