'Getting network error when try to user CustomParcelize and CustomParcelable in Kmm proyect

I was developing an Kotlin Multiplatform proyect, where I try to make some network calls and keep into a SQLDelight database.

So I try to create a custom Parcelable and Pacelize, using actual/expect behaviour of kmm.

So in my in my androidApp module I declare my custom Parcelize and Parcelable actuals implementations:

actual typealias CommonParcelize = Parcelize
actual typealias CommonParcelable = Parcelable

And in my commonMain module:

@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
expect annotation class CommonParcelize()

@Suppress("NO_ACTUAL_FOR_EXPECT")
expect interface CommonParcelable

the @Suppress("NO_ACTUAL_FOR_EXPECT") I have to added because I haven't configure the actual ios part.

And the model class which I'm using is the following:

package com.jshvarts.kmp.model

import com.jshvarts.kmp.android.plataform.CommonParcelize
import com.jshvarts.kmp.android.plataform.CommonParcelable

@CommonParcelize
data class UnsplashPhoto(
  val id: String?,
  var description: String?,
  val urls: UnsplashPhotoUrls,
  val user: UnsplashUser
) : CommonParcelable {
  @CommonParcelize
  data class UnsplashPhotoUrls(
    val raw: String,
    val full: String,
    val regular: String,
    val small: String,
    val thumb: String
  ) : CommonParcelable

  @CommonParcelize
  data class UnsplashUser(
    val name: String,
    val username: String
  ) : CommonParcelable {
    val attributionUrl get() =
      "https://unsplash.com/$username?utm_source=ImageSearchApp&utm_medium=referral"
  }
}

So, regarding android app, when I launch and recover the network response, I get the following error:

INFO io.ktor.client.HttpClient - RESPONSE https://api.unsplash.com/search/photos?query=cats&page=1&per_page=10 failed with exception: kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class UnsplashPhoto. For generic classes, such as lists, please provide serializer explicitly.

The error references to an error as I'm using @Serializable annotation, instead of @Parcelize and @Parcelable annotation.

So I don't know if you have experience in some implementations like this in kmm, but anyway, take thanks in advance !

[EDIT]

I made some update, removing the @Suppress("NO_ACTUAL_FOR_EXPECT") in the expect interface Parcelable, and I¡ve implemented in the ios part as empty actual:

`//IOSMain
actual interface CommonParcelable

and my other actual of common module are these:

//Common

@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
expect annotation class CommonParcelize()

expect interface CommonParcelable

And Android Module

//Android
actual typealias CommonParcelable = Parcelable

actual typealias CommonParcelize = Parcelize

And I'm still getting this error, as the CustomParcelable class doen't exist in IOSMain:

Expected interface 'CommonParcelable' has no actual declaration in module KmpMVVMGooglePay.shared.iOSMain for Native

Thank in advance for the help !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source