You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When deserializing, Transit field of parent class use its default value instead of the value from subclass constructor
To Reproduce
@Serializable
sealed class Parent(
@Transient val foo: Long = 0L
)
@Serializable
data class Child(
val anything: Unit = Unit
): Parent(System.currentTimeMillis())
// main
Json.encodeToString<Parent>(Child()).apply {
println(this)
Json.decodeFromString<Parent>(this).apply {
println(this)
println(this.foo)
}
}
In my actual business, foo will be some dynamic values, each subclass is different, and even the type may be different, so I used @Transitient, and passed in the corresponding value when the subclass constructor called the parent class constructor, but after deserialization, the default value of the parent class was directly used.
IDE version (if bug is related to the IDE) IntelliJ IDEA 2024.2/Android Studio Koala 2024.1 Patch 2
The text was updated successfully, but these errors were encountered:
Gargantua7
changed the title
Deserializing, Transit field use default value instead of the values from subclass constructor
Deserializing, Transitient field use default value instead of the values from subclass constructor
Aug 16, 2024
Describe the bug
When deserializing, Transit field of parent class use its default value instead of the value from subclass constructor
To Reproduce
In my actual business,
foo
will be some dynamic values, each subclass is different, and even the type may be different, so I used@Transitient
, and passed in the corresponding value when the subclass constructor called the parent class constructor, but after deserialization, the default value of the parent class was directly used.Expected behavior
It should use value from subclass constructor
Environment
The text was updated successfully, but these errors were encountered: