Class ConfigurableFieldSanitizer<T>

java.lang.Object
io.github.rabinarayanpatra.sanitizer.core.ConfigurableFieldSanitizer<T>
Type Parameters:
T - the type of the field
All Implemented Interfaces:
FieldSanitizer<T>
Direct Known Subclasses:
TruncateSanitizer

public abstract class ConfigurableFieldSanitizer<T> extends Object implements FieldSanitizer<T>
Base class for sanitizers that accept configuration parameters.

Subclasses receive key-value parameters from the @Sanitize annotation via configure(Map) before any sanitization calls. Parameters are specified using the params attribute of @Sanitize:

 @Sanitize(using = TruncateSanitizer.class, params = "maxLength=100")
 private String description;
 
Multiple parameters can be separated by commas:
 @Sanitize(using = MaskSanitizer.class, params = "reveal=6,character=X")
 private String accountNumber;
 
Since:
1.1.0
  • Constructor Details

    • ConfigurableFieldSanitizer

      protected ConfigurableFieldSanitizer()
      Default constructor.
  • Method Details

    • configure

      public void configure(Map<String,String> params)
      Called by the framework after instantiation to provide configuration parameters from the annotation.
      Parameters:
      params - the configuration key-value pairs; never null, may be empty
    • getParams

      protected Map<String,String> getParams()
      Returns the configuration parameters.
      Returns:
      unmodifiable map of parameter key-value pairs
    • getParam

      protected String getParam(String key, String defaultValue)
      Returns a configuration parameter value, or a default if not present.
      Parameters:
      key - the parameter key
      defaultValue - the default value if the key is absent
      Returns:
      the parameter value or the default
    • getIntParam

      protected int getIntParam(String key, int defaultValue)
      Returns a configuration parameter as an integer, or a default if not present or not parseable.
      Parameters:
      key - the parameter key
      defaultValue - the default value if the key is absent or invalid
      Returns:
      the parameter value as int, or the default
    • parseParams

      public static Map<String,String> parseParams(String paramString)
      Parses a comma-separated key=value parameter string into a map.
      Parameters:
      paramString - the raw parameter string from the annotation
      Returns:
      a mutable map of parsed key-value pairs