0

I use kotlinx.serialization on Kotlin native project, I a defined Super class for my models and all of the models extends from it. I defined a function to called toJSON() for serialize variables and fields inside model that all of class models have it.

@Serializable
open class Model {
   fun toJSON(): String = JSON.stringify(this);
}

And I created a subclass

class Me : Model() {
  var name:String = "Jack";
}

but when I invoke JSON.stringify(this), IDE get a Warning to me:

This declaration is experimental and its usage must be marked with '@kotlinx.serialization.ImplicitReflectionSerializer' or '@UseExperimental(kotlinx.serialization.ImplicitReflectionSerializer::class)'

I paid attention and I used @ImplicitReflectionSerializer annotation while not worked. Where is my problem?

ImanX
  • 789
  • 6
  • 23

1 Answers1

2

This is discussed here. It's the particular overload you're using which is still experimental. So your options are either to use the other overload (which takes in a serializer) or to use one of the annotations mentioned in the error message. If you look at the answer to the question I linked (and the comments following it), you'll see it talks about using @UseExperimental and where it should be used.

Yoni Gibbs
  • 6,518
  • 2
  • 24
  • 37