https://github.com/javiercanillas/jackson-masker
Sensitive Data Masker for ObjectMapper
https://github.com/javiercanillas/jackson-masker
jackson-objectmapper sensitive sensitive-data-exposure sensitive-data-security
Last synced: 6 months ago
JSON representation
Sensitive Data Masker for ObjectMapper
- Host: GitHub
- URL: https://github.com/javiercanillas/jackson-masker
- Owner: javiercanillas
- License: apache-2.0
- Created: 2021-06-03T18:22:36.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-11-03T03:14:23.000Z (over 1 year ago)
- Last Synced: 2025-07-31T07:34:09.943Z (12 months ago)
- Topics: jackson-objectmapper, sensitive, sensitive-data-exposure, sensitive-data-security
- Language: Java
- Homepage:
- Size: 308 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jackson-masker
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.
[](https://github.com/javiercanillas/jackson-masker/actions/workflows/maven-build.yml)
[](https://sonarcloud.io/dashboard?id=javiercanillas_jackson-masker)
[](https://sonarcloud.io/dashboard?id=javiercanillas_jackson-masker)
---
## Types supported
- String
- List\
- Set\
- String[]
- Map, String>
**Note:** If you consider a type might be missing or you like it on this list, feel free to contact [me](https://github.com/javiercanillas/jackson-masker/issues).
## How to use
Lets suppose you have an entity that has an email as part of its attributes:
```java
class EntityA {
String email;
...
}
```
Well, with this class you can annotate this attribute as sensitive data like this:
```java
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:
```java
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:
```json
{
"id": "********"
}
```
Furthermore, you can customize the masking character and if you want to
leave some first and last characters.
```java
@MaskString(keepInitialCharacters = 1, keepLastCharacters = 4, maskCharacter = '-')
String id;
```
The produced json in this case would be:
```json
{
"id": "a---1234"
}
```
More examples on test and [wiki](https://github.com/javiercanillas/jackson-masker/wiki)
## How to install
If you prefer to use maven central releases, you can find it [here](https://search.maven.org/artifact/io.github.javiercanillas/jackson-masker). Also, if you support [Jitpack.io](https://jitpack.io/) you can find it [here](https://jitpack.io/#javiercanillas/jackson-masker)