Print Kotlin data class instances as constructor statements using KSP
// readme
DeepPrint
A utility for printing kotlin data classes with the same syntax as their primary constructor.
Benefits:
- Data classes are easier to read in logs, as they now look like pretty JSON.
- Creating a replica object just involves copying and pasting.
Don’t print with the default toString() like this in your logs:
ThreeClassesDeep3(age=55, person=SamplePersonClass(name=Dave, sampleClass=SampleClass(x=0.5, y=2.6, name=A point)), sampleClass=SampleClass(x=0.5, y=2.6, name=A point))
Use deepPrint() or deepPrintReflection() to print this instead:
ThreeClassesDeep3(
age = 55,
person =
SamplePersonClass(
name = "Dave",
sampleClass =
SampleClass(
x = 0.5f,
y = 2.6f,
name = "A point",
),
),
sampleClass =
SampleClass(
x = 0.5f,
y = 2.6f,
name = "A point",
),
)
KSP vs. Reflection
DeepPrint offers 2 implementations: 1 using KSP and the other using reflection. They have similar functionality, but don’t have exact parity. This is partly due to the limitations of reflection, and partly because some features have not been added yet.