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

java.util.NoSuchElementException: List is empty when decodeFromJsonElement with nullable type #1035

Closed
tom5079 opened this issue Sep 3, 2020 · 0 comments
Assignees

Comments

@tom5079
Copy link
Contributor

tom5079 commented Sep 3, 2020

Describe the bug
java.util.NoSuchElementException is raised when decodeFromJsonElement with nullable type is called

To Reproduce

@Serializable
data class A(val a: Int)

@Test
fun test() {
    val a = A(42)
    
    val json = Json.encodeToString(a)
    val jsonElement = Json.parseToJsonElement(json)
    
    print(Json.decodeFromString<A?>(json))               // A(a=42)
    print(Json.decodeFromJsonElement<A?>(jsonElement))   // java.util.NoSuchElementException
}

Expected behavior
Successful decode

Environment

  • Kotlin version: 1.4.0
  • Library version: 1.0.0-RC
  • Kotlin platforms: JVM
  • Gradle version: 6.3
@qwwdfsad qwwdfsad self-assigned this Sep 3, 2020
qwwdfsad added a commit that referenced this issue Sep 3, 2020
Also, fix the same for Hocon, but do not generalize it too frequently.

Fixes #1035
qwwdfsad added a commit that referenced this issue Sep 11, 2020
Also, fix the same for Hocon, but do not generalize it too frequently.

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

No branches or pull requests

3 participants