0

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?

Artefacto
  • 96,375
  • 17
  • 202
  • 225
  • Similar to https://stackoverflow.com/questions/47129953/custom-jackson-serializer-on-specific-fields – dnault Oct 04 '19 at 19:29
  • Take a look at [Jackson custom serialization and deserialization](https://stackoverflow.com/questions/55249054/jackson-custom-serialization-and-deserialization) – Michał Ziober Oct 04 '19 at 19:45

0 Answers0