https://kotlinlang.org logo
#http4k
Title
# http4k
d

dave

04/09/2019, 11:23 AM
@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

Tom Ellis

04/09/2019, 11:42 AM
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

dave

04/09/2019, 12:17 PM
Interesting - we're using convertValue instead of readValue. Not sure of the difference. Will have to investigate
👍 1
r

Riku

04/09/2019, 1:08 PM
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

dave

04/09/2019, 1:11 PM
@Riku what types didn't work for you with the default version?
r

Riku

04/09/2019, 1:13 PM
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

dave

04/09/2019, 1:14 PM
is that a SQL Timestamp?
r

Riku

04/09/2019, 1:14 PM
yeah that is my blurry memory
might run it tonight when at home just to check
d

dave

04/09/2019, 1:15 PM
cool we can probably add that to the standard mappings
(let me know if we need to) 🙂
r

Riku

04/09/2019, 1:16 PM
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

dave

04/09/2019, 1:21 PM
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

Riku

04/09/2019, 2:19 PM
Ours are strings. now i wonder if we even typed them correctly 😆. Well if it aint broke...
2 Views