Unreliable serialization in output string (kotlinx date time types)
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
For now as a workaround i initialize these fields in the init block,
Ok all good for me, thank you