I want to transform sensitive strings in Jackson to something like "<removed>"
. Ideally, something like:
interface Scrubber {
String scrubString(String str);
boolean shouldScrubValue(String key);
// String keys are never themselves scrubbed
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD})
public @interface Serializable {
public boolean value() default true;
}
class ClassToBeSerialized {
String nonScrubbedString;
@Scrub
String scrubbedString;
// deep values are scrubbed too unless marked otherwise
@Scrub
Map<String, Object> map;
@Scrub
IncludedClass obj;
}
class IncludedClass {
@Scrub(false)
String nonScrubbedString;
Map<String, Object> map; // is scrubbed if included from ClassToBeSerialized
}
The Scrubber
instance, I can include it as an Jackson attribute, but what's the best way to go about the rest?