Is there a easy way to "pretty print" toString of ...
# getting-started
u
Is there a easy way to "pretty print" toString of a dataclass (indentations, new lines etc) ?
d
I think the only way is to override the toString function for the data class.
s
I think you could potentially create an extension function on
Any
that does pretty printing if it's standard across all your data classes
d
@Steven McLaughlin But this will affect not only data classes. So for other developers this maybe a surprise.
s
Sure, I'd probably call it like
toPrettyString()
or something explicit.
Idk, maybe not the best solution, but it's something I'd probably consider depending on the scope of my project
r
@ursus Don't know your use case, but a serialization library like kotlinx.serialization or Jackson might be a consideration instead?
u
@robin yea using json was my plan B