toStringByReflection

fun toStringByReflection(obj: Any, showReducedOnly: Boolean = true): String

Converts obj into a string representation using reflection.

This method tries to achieve the same effect as org.apache.commons.lang3.builder.ReflectionToStringBuilder, but with the following differences:

  • As opposed to using an exclusion policy, this method uses an inclusion policy, i.e. only serializing fields marked with the AllowToStringReflection dev.ust.zinc.grader.annotation. All other fields are hidden by "...".

  • A "reduced mode" is available, meaning to only serialize fields marked with AllowToStringReflection.showInReduced as true. This is useful for providing a simple and a detailed class information string.

  • This method supports additional Kotlin features, such as lateinit properties. In particular, if a lateinit property is accessed before it is initialized, <lateinit:uninitialized> will be displayed.

In essence, this method resembles like the toString method of data classes.