Jakub Gwóźdź
01/22/2024, 10:04 AMinternal fun formatValue(value: Any?): Any =
when (value) {
null -> "null"
is CharSequence -> "\"$value\""
is Char -> "'$value'"
is Iterable<*> -> if (value.javaClass.preferToString()) value.toString() else value.map(::formatValue)
is Byte -> "0x${value.toString(16)}"
is ByteArray -> "0x${value.toHex()}".truncate()
...
Is there a reason why if (value.javaClass.preferToString()...
is only in Iterable<*> and not on any class?
Reason I’m asking is because I have things like expectThat(jsonObject1).isEqualTo(jsonObject2)
(from kotlinx.serialization) and it works just fine, but whenever there is a fail, I don’t see beautiful json (like from jsonObject2.toString()
), but rather a mess with the =
chars (caused by line 42).