Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created May 14, 2020 06:21
Show Gist options
  • Select an option

  • Save monkey-codes/c5cc163b92bca3e96cdbdccff5b83289 to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/c5cc163b92bca3e96cdbdccff5b83289 to your computer and use it in GitHub Desktop.
PII Masking ToStringBuilder
class PIIMaskingToStringBuilder(value: Any?, toStringStyle: ToStringStyle = RecursivePIIMaskingToStringStyle) :
ReflectionToStringBuilder(value, toStringStyle) {
override fun getValue(field: Field?): Any? {
return field?.getAnnotation(PII::class.java)?.let {
mask(super.getValue(field))
} ?: super.getValue(field)
}
companion object {
fun toString(value: Any?): String = PIIMaskingToStringBuilder(value, RecursivePIIMaskingToStringStyle).toString()
fun mask(value: Any?) =
Configuration.dataMaskingFunction.mask(value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment