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.

Unreliable serialization in output string (kotlinx date time types)

See original GitHub issue

Describe the bug When I try to serialize an instance of this object with kotlinx serialization, the resulting string is inconsistent, sometimes (very rarely) it outputs test0 and test1 fields in the output, but more often than not those fields are not in the result as if they were null ?

Also while debugging these two fields are considered optional (elementsOptionality field) in the generated serializer class, so is id field but this is expected

To Reproduce Simply deserialize this class

@Serializable data class TestX( val id: String? = null, val code: Int, val reason: String, val message: String?, val test0: LocalDateTime = LocalDateTime(2020, 5, 20, 17, 0, 0) ) { val test1 = Clock.System.now() }

and then val jsonString = Json.encodeToString(test)

Expected behavior

Environment

  • Kotlin version: 1.5.22
  • Library version: 1.2.2, datetime version: 0.2.1
  • Kotlin platforms: JVM
  • Maven 3

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
master-bytes-kraftercommented, Aug 8, 2021

For now as a workaround i initialize these fields in the init block,

0reactions
master-bytes-kraftercommented, Aug 9, 2021

Ok all good for me, thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

kotlinx-datetime 0.2.0 Is Out | The Kotlin Blog
The default serializer is based on an ISO 8601 string representation of a type and uses toString() / parse() to serialize and deserialize...
Read more >
Kotlinx.Serialization deserializing dates - Stack Overflow
I'm having a hard time finding documentation ...
Read more >
Lettuce Reference Guide
This enables exchange of data between threads with well-defined memory usage, avoiding unnecessary intermediate buffering or blocking. 1.3. Non- ...
Read more >
Spring Data MongoDB - Reference Documentation
Jackson Modules to de-/serialize types like Point and Distance , or store specific ones, depending on the Spring Data Module used.
Read more >
The jOOQ Release Note History
We've added a cache for input/output SQL string pairs to heavily speed up the integration; We're now delaying bind variable type inference to...
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