I have a custom setter in my Lombok-based POJO:
@Data
@Builder
public class User {
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
private String password = null;
public void setPassword(String password) {
Assert.notNull(password);
this.password = ENCODER.encode(password);
}
but when I use the Lombok generated builder:
User user = User.builder()
.password(password)
.build();
my custom setter is not invoked, and so the password is not encoded. This makes me sad.
My custom setter is, of course, invoked when I use it directly:
public void changePassword(String password, User user) {
user.setPassword(password);
}
What can I do to have Lombok's builder use my custom setter?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…