I see ```fun <T> AutoMappingConfiguration&lt...
# http4k
d
I see
Copy code
fun <T> AutoMappingConfiguration<T>.withStandardMappings() = apply {
    text(duration())
    text(uri())
    text(url())
    text(uuid())
    text(regexObject())
    text(instant())
    text(yearMonth())
    text(localTime())
    text(localDate())
    text(localDateTime())
    text(zonedDateTime())
    text(offsetTime())
    text(offsetDateTime())
    text(zoneId())
    text(zoneOffset())
    text(eventCategory())
    text(traceId())
    text(samplingDecision())
    text(throwable())
    text(locale())
    int({ Status(it, "") }, Status::code)
}
which is really handy, but I’d like to change the handling for just Throwables. Can anyone thing of a good way to override the standards? Context - I have some `Event`s that are also `Exception`s (try it, it’s really handy), but they are currently rendered with
.toString()
not as structured objects
d
Moshi has a the concept of
addLast
. Not sure if there is the equivalent in Jackson, but might be worth having a look
🙏 1
d
Wait what?
Copy code
fun throwable() = BiDiMapping({ throw Exception(it) }, Throwable::asString)
Deserializing a throwable throws an exception?
d
yes - because you cannot deserialise an exception!
d
🤯
a
Not with that attitude! I don't really see why you shouldn't 🤔 . Apart from it being a silly idea and all 🙃 .
d
I suppose the issue is that it is serializing Throwable, and who knows what subclass it should deserialize. Feels a bit more like
error("Cannot deserialize a Throwable with message $it")
but I can see the current is less typing
a
Yeah, usually the BiDiMappings deal with a concrete class. This is the first time I've noticed one using an abstract class. So it would never be possible to get the same type back. I assume what you're trying to do is add your own mapper to override this default behaviour?
d
Well what I really want to do is render a data class that is also an Exception as the data class fields, not the Throwable.toString()