Sensitive information (such us emails, IDs or phone numbers) is a serious problem to deal with. If you have objects that are logged or write into files where masking is required, and you are already using Jackson ObjectMapper solution in your application, this library might be of some help.
- String
- List<String>
- Set<String>
- String[]
- Map<?, String>
Note: If you consider a type might be missing or you like it on this list, feel free to contact me.
Lets suppose you have an entity that has an email as part of its attributes:
class EntityA {
String email;
...
}
Well, with this class you can annotate this attribute as sensitive data like this:
import MaskString;
class EntityA {
@MaskString
String id;
public String getId() {
return this.id;
}
public void setId(String value) {
this.id = value;
}
}
And it will be masked when writing using a Jackson ObjectMapper like this:
ObjectMapper mapper = new ObjectMapper();
final ObjectWriter maskedWriter = mapper.writerWithView(io.github.javiercanillas.jackson.masker.view.Masked.class);
final EntityA obj = new EntityA();
obj.setId("abcd1234");
maskedWriter.writeValueAsString(obj);
And it will produce:
{
"id": "********"
}
Furthermore, you can customize the masking character and if you want to leave some first and last characters.
@MaskString(keepInitialCharacters = 1, keepLastCharacters = 4, maskCharacter = '-')
String id;
The produced json in this case would be:
{
"id": "a---1234"
}
More examples on test and wiki
If you prefer to use maven central releases, you can find it here. Also, if you support Jitpack.io you can find it here