A Kotlin compiler plugin that generates redacted toString()
implementations.
Inspired by the auto-value-redacted
extension for AutoValue.
Include the gradle plugin in your project, define a @Redacted
annotation, and apply it to any
properties that you wish to redact.
@Retention(SOURCE)
@Target(PROPERTY)
annotation class Redacted
data class User(val name: String, @Redacted val phoneNumber: String)
When you call toString()
any @Redacted
properties are hidden:
User(name=Bob, phoneNumber=██)
If your annotation is applied to the class, then toString()
will emit a single replacement string:
@Retention(SOURCE)
@Target(CLASS)
annotation class Redacted
@Redacted
data class SensitiveData(val