Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.1 SerializationException: Can't locate argument-less serializer #278

Closed
hannpet opened this issue Nov 24, 2018 · 12 comments
Closed

v0.9.1 SerializationException: Can't locate argument-less serializer #278

hannpet opened this issue Nov 24, 2018 · 12 comments
Labels

Comments

@hannpet
Copy link

hannpet commented Nov 24, 2018

@Serializable
data class Data(var txt: String)

@UseExperimental(ImplicitReflectionSerializer::class)
fun main() {
    val myData = Data("Blah blah")

    val js = JSON.unquoted.stringify(myData)
    println(js)
}

will throw

Exception in thread "main" kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class MainKt$main$Data. For generic classes, such as lists, please provide serializer explicitly.
	at kotlinx.serialization.PlatformUtilsKt.serializer(PlatformUtils.kt:28)
	at kotlinx.serialization.context.ContextKt.getOrDefault(Context.kt:39)
	at MainKt.main(Main.kt:15)
	at MainKt.main(Main.kt)

I'm on version 0.9.1 which fixed Bug #250. I'm a bit confused now, because it seems like the same Bug is popping up on me now. Did I miss something here?

@sandwwraith
Copy link
Member

This issue seems unrelated to 250 and is more likely caused by non-applied plugin or another problems with your project setup

@MaxElkin
Copy link

MaxElkin commented Nov 24, 2018

This issue seems unrelated to 250 and is more likely caused by non-applied plugin or another problems with your project setup

Exactly.

I fixed this issue after fix of plugin application. Now it's placed in root build.gradle.kts in plugins { ... } block

@markusmoormann
Copy link

@sandwwraith is this currenlty supposed to work without delegating to gradle? I'm using IntelliJ IDEA 2018.3.1
Build #IU-183.4588.61, built on December 4, 2018
Kotlin Plugin Version is: 1.3.11-release-IJ2018.3-1
I still get this error in IDEA

@sandwwraith
Copy link
Member

@markusmoormann If setup in Gradle is incorrect, it would not be correctly imported to IDEA, and therefore this error would emerge both in Gradle and IDEA builds.

@markusmoormann
Copy link

I've imported the example-jvm project. Once with maven, once with gradle, non of them worked.
What do you mean with "if setup in gradle is incorrect"? I've just installed gradle and created a really simple maven project according to quick example. Data.serializer() still brings up Error:(17, 31) Kotlin: Unresolved reference: serializer

@sandwwraith
Copy link
Member

So you're using Gradle or Maven? For Maven, I can confirm that there is an import problem: #307

@markusmoormann
Copy link

@sandwwraith I'm using maven. At least I can confirm that importing the example-jvm und fiddling around with the respositories I can compile and start the app in IDEA

@cvelinciuc
Copy link

I'm using Gradle and I get the same exception when I try to JSON.stringify a Map of <String, Any>. Yet it works with Map<String, SomeClass>

@sandwwraith
Copy link
Member

@msacras You can't just serialize Any without any reflection or polymorphism. You need either specify concrete serializer for it or try to use PolymorphicSerializer (but #101)

@mochadwi
Copy link

This issue seems unrelated to 250 and is more likely caused by non-applied plugin or another problems with your project setup

Exactly.

I fixed this issue after fix of plugin application. Now it's placed in root build.gradle.kts in plugins { ... } block

how do we setup this in our android project?

@mochadwi
Copy link

mochadwi commented Mar 6, 2019

This issue seems unrelated to 250 and is more likely caused by non-applied plugin or another problems with your project setup

Exactly.
I fixed this issue after fix of plugin application. Now it's placed in root build.gradle.kts in plugins { ... } block

how do we setup this in our android project?

Looks like here's how to solve it:

  1. using plugins https://github.com/Kotlin/kotlinx.serialization#gradle-with-plugins-block
  2. or gradle https://github.com/Kotlin/kotlinx.serialization#gradle

@sandwwraith
Copy link
Member

If you have any questions left, feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants