Interface ValueMaskerContext


public interface ValueMaskerContext
Represents the original value that is currently being masked. The context is passed to ValueMasker.maskValue(ValueMaskerContext) to allow the implementation to replace the JSON value with a custom mask.

The JSON value is represented by a byte array to provide a way to access the content of the original value, based on index. The index includes the JSON value in its entirety which means that for example for strings the opening and closing quotes are included. The reason for this is that the API becomes more flexible as it enables strings to be replaced by null, for example.

  • Method Summary

    Modifier and Type
    Method
    Description
    asString(int fromIndex, int length)
    Returns a string representation of the original JSON value.
    int
    Returns the length of the original value that is being masked in bytes.
    int
    countNonVisibleCharacters(int fromIndex, int length)
    Returns the number of non-visible, human-readable characters in the original value.
    byte
    getByte(int index)
    Retrieve the byte at the given index in the original value that is being masked.
    invalidJson(String message, int index)
    Create an InvalidJsonException with the given message and index relative to the value (i.e.
    void
    replaceBytes(int fromIndex, int length, byte[] mask, int maskRepeat)
    Indicates that the bytes of the original value (or part of the value) needs to be replaced with a mask.
  • Method Details

    • getByte

      byte getByte(int index)
      Retrieve the byte at the given index in the original value that is being masked.
      Parameters:
      index - the index in the original value between 0 (inclusive) and byteLength() (exclusive)
    • byteLength

      int byteLength()
      Returns the length of the original value that is being masked in bytes.
    • replaceBytes

      void replaceBytes(int fromIndex, int length, byte[] mask, int maskRepeat)
      Indicates that the bytes of the original value (or part of the value) needs to be replaced with a mask.

      Note: the replacement might result in an invalid JSON, make sure to include opening and closing quotes when the replacement is a string value.

      Parameters:
      fromIndex - index from which the replacement should start. For string values, the opening quote is included
      length - length of the value to mask. relative to the fromIndex. For string values the closing quote is included
      mask - the mask to replace the original value with
      maskRepeat - number of times to repeat the mask, useful for masking digits or characters, for static masks the value should be 1.
      See Also:
    • countNonVisibleCharacters

      int countNonVisibleCharacters(int fromIndex, int length)
      Returns the number of non-visible, human-readable characters in the original value.
      Parameters:
      fromIndex - index from which the counting should start
      length - length of the value to count to, relative to the fromIndex
      Returns:
      number of non-visible characters in the value
      See Also:
    • asString

      String asString(int fromIndex, int length)
      Returns a string representation of the original JSON value.

      Note: this INCLUDES the opening and closing quotes for string values

    • invalidJson

      InvalidJsonException invalidJson(String message, int index)
      Create an InvalidJsonException with the given message and index relative to the value (i.e. an index between 0 and byteLength()).
      Parameters:
      message - error message
      index - relative index where the JSON contains invalid sequence
      Returns:
      the exception to be thrown