question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.ClassNotFoundException: kotlinx.serialization.ElementValueEncoder

See original GitHub issue

Describe the bug I am building a plugin for minecraft spigot and wanted to store / load settings using Kotlin’s serializable and charleskorn’s Yaml. However, when calling com.charleskorn.kaml.Yaml.stringify with a serializable data class’ serializer().list from import kotlinx.serialization.builtins.list I am getting the following error: Caused by: java.lang.ClassNotFoundException: kotlinx.serialization.ElementValueEncoder https://pastebin.com/C9hZB7yB

Code that is causing the issue

Yaml.default.stringify(Gauntlet.serializer().list, gauntlets)

Where Gauntlet is a @Serializable

This is my Gradle build file

plugins {
	id 'java'
	id 'org.jetbrains.kotlin.jvm' version "$kotlin_version"
	id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
	id 'com.github.johnrengelman.shadow' version '2.0.4'
}

group 'com.krulvis.gauntlet'
version '1.0'

repositories {
	mavenLocal()
	mavenCentral()
	maven {
		name = "spigot"
		url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
	}
}

dependencies {
	implementation "com.charleskorn.kaml:kaml:0.15.0"
	implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
	api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.20.0"
	compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.20.0"
	compileOnly("org.spigotmc:spigot-api:${minecraft_version}-R0.1-SNAPSHOT")
}

compileKotlin {
	kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
	kotlinOptions.jvmTarget = "1.8"
}

I read somewhere on another issue that some class couldn’t be found and the dependency should be loaded as api rather than compile in dependencies in the gradle build file. I tried both, which didn’t resolve the issue.

Expected behavior Stringify list of serializable data classes Environment

  • Kotlin version: 1.3.72
  • Library version: 0.20.0
  • Kotlin platforms: JVM
  • Gradle version: 6

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Krulviscommented, Jul 13, 2020

Thanks for clearing that up! Really appreciate the effort you guys put into this!

0reactions
qwwdfsadcommented, Jul 13, 2020

Why does it search for an old non-existed class?

Because your dependency (implementation "com.charleskorn.kaml:kaml:0.15.0" or maybe spigot-api) is compiled against older version of kotlinx.serialization where this class actually exists.

You have your application that depends on 0.20.0 version and kaml that depends on 0.15.0 version. These versions are incompatible, so either kaml should be updated, or your own dependency on serialization downgraded back to 0.15.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoClassDefFoundError kotlinx/serialization ... - GitHub
I'm using kotlinx-datetime and mockk. I'm trying to mock TimeZone.currentSystemDefault() at a below code, but error occurs, java.lang.
Read more >
NoClassDefFoundError kotlinx serialization - Stack Overflow
I have a kotlin multiplatform project and I need to serialize a class. I have included the following dependency ...
Read more >
kotlinx.serialization.internal.SerialClassDescImpl.<init> after ...
Unfortunately, serialization 0.14.0 is not compatible with 1.3.70 due to changed APIs. Today's release, 0.20.0, fix incompatibilities and also brings a lot of ......
Read more >
How can I fix random Kotlin exceptions when using the Java ...
Symptom: you receive random exceptions relating to Kotlin, or other exceptions similar to: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Could ...
Read more >
Kotlinx serialization with Spring Boot - Kotlin Discussions
Has anyone tried this? The code that works great with KTOR rest seems to not work correctly on the spring boot side.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found