E.g.:
data class Key(
val id: Int,
val secret: String,
val description: String?
)
To exclude or mask special properties like passwords or credit card numbers:
Key(
id = 1,
secret = "foo",
description = "bar"
).toString()
// Key(id=1, description=bar)
// or
// Key(id=1, secret=********, description=bar)
Or to ignore properties with null
s to make the resulting string more readable:
Key(
id = ...,
secret = ...,
description = null
).toString()
// Key(id=...)
// or
// Key(id=..., secret=...)
Implementing toString()
each time may be very tedious and error-prone, especially if you have too many properties in the class.
Is there any (upcoming) solution for this problem (e.g. like Lombok for Java)?