<@UG2RK4C10> this is pretty standard Jackson behav...
# http4k
d
@Tom Ellis this is pretty standard Jackson behaviour - when in doubt it does deserialise using Maps (we see the same with generic lists). It's nothing to do with http4k per-se, but about how you set up the Jackson mapper instance and annotate the classes for deserialisation with something like
@JsonTypeInfo
. TBH, I generally try to make DTO objects as dumb as possible as I hate all the annotations.
t
hmm - the thing is if i just do this, it’s fine:
Copy code
val jacksonResult = jacksonObjectMapper().readValue<Result<MyClass>>(response.bodyString())
println(jacksonResult.body.message)
so i have a workaround, it would just be nice to use the lens…
d
Interesting - we're using convertValue instead of readValue. Not sure of the difference. Will have to investigate
👍 1
r
I don't know if this is related at all but I also found cases when default mapper didn't work for mysterious reasons (or reasons I never looked into) but using our mapper always worked fine
Copy code
val mapper = KotlinModule()
    .asConfigurable()
    .withStandardMappings()
    .done()
    .registerModule(JodaModule())
    .disableDefaultTyping()
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    .configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, true)
    .configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true)
    .configure(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS, true)
    .configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true)
actually I now realize this is nothing to do with your case
d
@Riku what types didn't work for you with the default version?
r
I can't remember off hand, there were two cases
Copy code
data class EventInDto(
    val name: String,
    val sponsor: String,
    val contact: String,
    val date: Timestamp,
    val details: String,
    val location: String,
    val status: EventStatus = EventStatus.PLANNING,
    val maxParticipants: Int,
    val registrationOpens: Timestamp,
    val volume: Int,
    val sponsorLink: String
)`
that was one
d
is that a SQL Timestamp?
r
yeah that is my blurry memory
might run it tonight when at home just to check
d
cool we can probably add that to the standard mappings
(let me know if we need to) 🙂
r
ah hey, we are using readValue now too
because we validate the json, we are doing
Body.string(ContentType.APPLICATION_JSON).map { json -> EventInDto.from(json) }.toLens()
and inside
from
readValue
but then else where we do use the mapper directly in the lens
and I think there was another spot it also fixed an issue
I guess that use of the lens is kind of hacky
d
i'll fix it up to use readValue and also to support Timestamp, then you can remove the hack!
and in future, please let us know if you think you need to hack around stuff ... I am figuratively dying of professional embarrassment here 😉
@Riku presumably timestamps are transmitted as longs over the wire - or strings?
hmm - timestamp as a number actually seems a little dodgy. think we'll release with the other fix and look at timestamp later. 🙂
r
Ours are strings. now i wonder if we even typed them correctly 😆. Well if it aint broke...