How to mask value when logged by using @ToString annotation or by creating new annotation

Viewed 1718

I would like to create my own custom annotation, i'm using Spring framework.

when someone annotate his POJO class a code behind will trigger methods.

For example @Sensetive(values = "accountNumber") when annotate on below class

public class User {
   protected String user = "";
   protected String code = "";
   protected String accountNumber = "";
}

will call a method that when logging the values they will appear masked ( for example accountNumber = "12345" -> masked accountNumber = XXXX5).

I'm aware of @ToString annotation that can exclude the value completely when calling toString method, but is there possibility to mask it?

1 Answers
Related