https://kotlinlang.org logo
#serialization
Title
# serialization
h

hastebrot

04/13/2018, 9:56 AM
I noticed a lot of work on moshi and kotlin code generation using kotlinpoet. https://github.com/square/moshi
g

gildor

04/13/2018, 9:58 AM
Cool. Looks like moshi will generate type adapters for Kotlin Like Kotshi
h

hastebrot

04/13/2018, 9:59 AM
currently I hacked my json “serializer”.
Copy code
private fun simpleJsonAdapter(): JsonAdapter<JsonCommandList> {
    val moshi = Moshi.Builder().build()
    val listOfCommands = Types.newParameterizedType(
        List::class.java,
        Map::class.java
    )
    return moshi.adapter(listOfCommands)
}
Oh I didn’t know about kotshi. Will try it out.
but since the core of moshi is written in java (incl. okio) I’ll have to migrate to kotlinx.serializer sooner or later to build my multiplatform project
g

gildor

04/13/2018, 10:04 AM
Sure, you cannot use moshi for multiplatform (only as JVM implementation)
problem with moshi is a way how moshi works: uses java reflection, no way to port it for multiplatform
h

hastebrot

04/13/2018, 10:07 AM
yeah. kotlin.ser has a much bigger goal. multiple platforms and multiple formats (json, protobuf, …)
and the recent feature branch that uses kotlinx-io
16 Views