Is there any way to mask sensitive fields on the automatically generated "toString()" method in Java Records without overriding it? (i.e. Annotations)
i.e.
public record SomeRecord(..., String apiKey, String password, ...) { }
Please no "Use Lombok!" answers :)
I think you can wrap the sensitive info by the object:
record SensitiveInfo(String info) {
public String toString() {
// add your masking func here
}
// other necessary methods to use with info field
}
So in your SomeRecord:
record SomeRecord(..., SensitiveInfo apiKey, SensitiveInfo password)
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