This library works with reflection and helps to display an object as a string without using Kotlin datа classes. There are 2
extensions for this: Any.asString and Any.asString(). The extension works only with the current class. So for nested fields,
override the toString method with the same extension. Fields from super classes are also displayed.
dependencies {
implementation "com.github.g000sha256:AsString:1.0"
}
repositories {
maven { url "https://jitpack.io" }
}class Action(
val actionParam: String = "actionParam",
val data: Data = Data()
) {
override fun toString(): String {
return asString()
}
}
class Data(
val dataParam: String = "dataParam"
) {
override fun toString(): String {
return asString()
}
}val action = Action()
println("$action")displays a
Action(actionParam: actionParam, data: Data(dataParam: dataParam))
An extended example you can see here.