What would be a good kotlin replacement for Jackso...
# kotlin-native
a
What would be a good kotlin replacement for Jackson? We want to compile our data library to Swift and need to get rid of all Java-based dependencies
j
Do you have JSON library in Swift? You may create
actual
API for all functions you need around JSON and than use different
expected
parts for each platform - e.g. Jackson on JVM and some another library from Swift on the iOS side
e
a
Well, to be honest, the only thin right now used in our data library are Jackson annotations. Parsing is implemented by the consumers. But consumers for now are only Android and Kotlin-SpringBoot
e
It is also integrated into ktor http client for JVM and native
a
Now that we also want to add iOS as a consumer, I was thinking to add parsing logic into the data library and implement it with some kotlin parser
e
That is what
kotlinx.serlization
does for you. You don’t need to write any of the code. Just annotate your data classes as
@Serializable
a
What about when fields don’t match json?
This is, mostly, what we use from Jackson annotations
e
We have similar annotations for most needed features -
@SerialName
,
@Transient
and
@Optional
. If you need something else, file a request to https://github.com/kotlin/kotlinx.serialization/issues with your use-cases
a
Great, thanks, I’ll take a look
t
@elizarov hm, I thought that data classes aren't supported yet for native
c
is kotlinx serialization ready for use? last time i checked it was under heavy development and needed a separate plugin
e
It is still experimental, but it already supports native. Indeed, you need to use the plugin. That is the whole idea, so that you don’t have to manually or generate serialization code.
t
This issue should be updated if full serialization is supported for native: https://github.com/Kotlin/kotlinx.serialization/issues/86#issuecomment-412092412
e
^ @sandwwraith
s
I’ve updated information in the issue.
👍 1