https://kotlinlang.org logo
#ktor
Title
# ktor
s

sp

02/28/2019, 2:57 AM
also seems like your problem is due to directly mapping query params to a data class
t

tjb

02/28/2019, 2:57 AM
hmm
the
tags
in my example is the JSON body
s

sp

02/28/2019, 2:59 AM
Could you try and print tags and show us the output
t

tjb

02/28/2019, 3:01 AM
Capture.PNG
@sp ^
s

sp

02/28/2019, 3:02 AM
okay well that makes sense
your class is somehow being parsed to a LinkedHashMap
t

tjb

02/28/2019, 3:03 AM
i guess why? i was googling and it said jackson doesnt have enought information about the class but im not sure what that means
s

sp

02/28/2019, 3:03 AM
but it’s correctly parsing it as a list
doubt it
jackson fails with other errors
I would have a look ath documentation for the receive function
t

tjb

02/28/2019, 3:04 AM
ill take a look
interesting
it does not work with a
List
but serializes fine if only a single object
o

obobo

02/28/2019, 4:41 PM
Seems like the problem is that receive() loses the generic type information. Look at Extensions.kt in the jackson kotlin module, they wrap the generic information in a TypeReference. receive would have to do something similar, but I'm not sure how, since the wrapper would be specific to the content negotiation implementation.
a

andev

03/06/2019, 12:23 PM
t

tjb

03/11/2019, 5:20 PM
i just commented on this but is there a workaround for this?
o

obobo

03/11/2019, 11:13 PM
You could inject a jacksonObjectMapper directly into your controller and receive a String or byte array and parse that into your domain object.
t

tjb

03/20/2019, 2:41 AM
i came up with this extension function
Copy code
inline fun <reified T> String.serialize(): T {
  return jacksonObjectMapper().readValue(this)
}
for those interested
usage:
Copy code
val tags = call.receiveText().serialize<List<Tag>>()
4 Views