Hi. With http4k format moshi, how do we deserialis...
# http4k
a
Hi. With http4k format moshi, how do we deserialise the body, which is a list of objects? For example:
Copy code
data class User(val name: String)

val bodyLens = Body.auto<List<User>>().toLens() // What do i use instead of the auto to handle lists?
bodyLens(response)
a
Alright so changing List to Array fixes it all 🙂 Thanks
d
yep - it's a bit annoying and a common gotcha for raw lists, but there's not really much we can do TBH
a
No worries. I'm new to Moshi. I always used KotlinX Serialization but it makes us create too many models just so we can add the @Serializable. Moshi is a good improvement.
d
There's also Kotshi, which does auto-generation of adapters at compile time to avoid the need for reflection 🙂
a
Yes i use the Kotshi
a
Sometimes I just avoid serializing lists altogether. If I ever want to add pagination data, it's nice to already have a wrapper class to hold it all.
👍 3