Search code examples
androidkotlingsonkotlin-multiplatform

None of the arguments can be called with the agruments supplied with Gson


I have started working with a Kotlin Multiplatform library, and I make use of Gson on the android side to do some processes. Since I know iOS does not have support for Gson, I decided to create an expected function called convertToJson which has a return type of a class. However when I have the actual implementation, I get the following error:

None of the arguments can be called with the arguments supplied

This occurs at this line of code:

actual fun convertFromJson(json:String): ClassName {
    return Gson().fromJson(json, ClassName::class) // this is where the error lies
}

I also have an actual implementation of a function called convertToJson which does not give me an error, so I am wondering why the above mentioned convertFromJson function gives me an error.

Any help or advice will be highly appreciated.


Solution

  • Gson is implemented in java and its fromJson accepts an instance of java.lang.Class as the argument, so you should replace ClassName::class with ClassName::class.java, because the former gives you an instance of kotlin.reflect.KClass.