Kotlinx.serialization: Add support for Kotlin/Native

Created on 15 Feb 2018  Â·  14Comments  Â·  Source: Kotlin/kotlinx.serialization

Since Kotlin/Native 0.6 supports multiplattform projects, it would be nice to have also support for kotlin native.

https://blog.jetbrains.com/kotlin/2018/02/kotlinnative-v0-6-is-here/

feature question

Most helpful comment

Yes, Kotlin/Native support is in our plan and we've already started working at it :)

All 14 comments

Yes, Kotlin/Native support is in our plan and we've already started working at it :)

Is there an eta on Kotlin/Native support?

@sandwwraith I'm also curious about an ETA on kotlin/native support

@rytedesigns @Arne517 there is a K/N compatible version of this library, but the compiler plugin API is not available on Native yet. To try it out (remember, this is early preview), there are two options:

  • Use sourcegen branch and Kotlin source generator from there, which uses DSL to generate data classes with serializers compatible with library (see example-sourcegen folder and its buildSrc)
  • Use json-ast branch and jsonparser native module, which contains JSON parser and JSON tree model (but can't map it on data classes yet)

@sandwwraith is there an update you could give on K/N support? We're looking at some options for managing APIs on Android and iOS using K/N. Where could we follow the support for the compiler plugin API on Native?

@AndreasBackx no updates on compiler plugin for now :(

https://blog.jetbrains.com/kotlin/2018/07/kotlinnative-v0-8-released/

According to this kotlinx.serialization is now supported with kotlin/native. But I am still unable to use this.

@nish-d Support for native is limited for now and expressed as separate JSON parser. We are working in this direction.

I'd like to announce an early access preview of kotlinx.serialization plugin for Native. The showcase project can be found at https://github.com/sandwwraith/KotlinSerializationPlayground/tree/native_preview/ . Some rules of thumb:

  • Works with Kotlin/Native 0.9-dev-3770
  • Version of kotlinx.serialization plugin must be 0.7.0-eap-1, serialization runtime library 0.7.0-eap-3.
  • Kotlin version is 1.3-M2
    > These versions will be updated with every release, see corresponding gradle.properties for actual information
  • Kotlin Native Gradle plugin does not support compiler plugins yet, passing plugin option to compiler must be performed manually (see https://github.com/sandwwraith/KotlinSerializationPlayground/blob/native_preview/native/build.gradle#L40 , note the -unshaded suffix in maven coordinates).
  • Internal kotlinx.serialization API has been significantly changed to match corresponding KEEP, sources for 0.7.X build can be found in branch core_refactoring.

What works:

  • @Serializable classes with primitive or @Serializable properties
  • Standard collections
  • @Optional and @SerialName annotations

What does not work:

  • @Serializable classes with generics (except standard collections)
  • Enums and arrays (Array<T>, ByteArray, etc)
  • @Transient initializers and init blocks
  • @SerialInfo-based annotations

The showcase project has different version numbers than what you have mentioned.

@nish-d I can see correct versions: https://github.com/sandwwraith/KotlinSerializationPlayground/blob/native_preview/gradle.properties#L1
(notice that showcase project with native is located in native_preview branch, not master)

@sandwwraith In SerialImplicits.kt, it is noted that the code won't work with kotlin/native.
Does that mean protocolbuffer serialization/deserialization is not available yet for kotlin-native?

@daudrain It is available, but without the possibility to specify custom serial ids – all properties are enumerated in order starting from 1.

kotlinx.serialization plugin for native has been feature-complete for several latest releases, so I think this may be closed now. 🎉

Was this page helpful?
0 / 5 - 0 ratings