Sekret — risk-free toString() of Kotlin data class?

Problem

data class ViewState(
val username: String,
val password: String,
val isButtonEnabled: Boolean
)
// PS: never keep passwords in String
fun render(viewState: ViewState) {
logger.info("render $viewState")
...
}

Solution

data class Data(
val username: String,
@Secret val password: String
)
print(Data("james.bond", "123456"))// prints out
// Data(username=james.bond, password=■■■)

--

--

Senior Android Developer at Agoda

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store