Class TruncateSanitizer

java.lang.Object
io.github.rabinarayanpatra.sanitizer.core.ConfigurableFieldSanitizer<String>
io.github.rabinarayanpatra.sanitizer.builtin.TruncateSanitizer
All Implemented Interfaces:
FieldSanitizer<String>

public class TruncateSanitizer extends ConfigurableFieldSanitizer<String>
Configurable sanitizer that truncates strings to a maximum length.

Accepts the following parameters via @Sanitize(params = "..."):

  • maxLength — the maximum allowed length (default: 255)
  • suffix — appended when truncation occurs (default: empty). The suffix length is included in the maxLength limit.
 @Sanitize(using = TruncateSanitizer.class, params = "maxLength=100,suffix=...")
 private String description;
 
Since:
1.1.0
See Also:
  • Constructor Details

    • TruncateSanitizer

      public TruncateSanitizer()
      Default constructor.
  • Method Details

    • sanitize

      public @Nullable String sanitize(@Nullable String input)
      Truncates the input string to the configured maximum length.
      Parameters:
      input - the string to sanitize
      Returns:
      the truncated string, or null if input is null