Stage 2 changes - Xantier/multiplat-workshop GitHub Wiki

Taking a look at multiplatform serialization

Common

  • Model.kt
    • Adding serializable annotations to model data classes
    • Adding a serializer implementation for photo list
@Serializable
val photoListSerializer: KSerializer<List<Photo>> = Photo::class.serializer().list
  • gradle.build
    • Applying kotlinx-serialization plugin to the build
    • Adding needed dependency for multiplatform serialization
apply plugin: 'kotlinx-serialization'
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"

JVM

  • build.gradle
    • Adding needed serialization runtime
apply plugin: 'kotlinx-serialization'
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"

Adding serialization of returned JSON to list of our Photo objects

  • ApiClient.kt
val photoList = JSON.nonstrict.parse(photoListSerializer, returnable)

JS (same thing!)

  • build.gradle
    • Adding needed serialization runtime
apply plugin: 'kotlinx-serialization'
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
  • ApiClient.kt
    • Adding serialization of returned JSON to list of our Photo objects
val photoList = JSON.nonstrict.parse(photoListSerializer, returnable)
  • index.html
    • Add serialization.js script to the HTML
⚠️ **GitHub.com Fallback** ⚠️