The kdoc of Transient says:
Marks the JVM backing field of the annotated property as
transient, meaning that it is not part of the default serialized form of the object.
However this is not the case with the serialization plugin as it serializes transient properties.
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
@Serializable
data class Data(val a: Int) {
@Transient
val b = "Hello"
}
fun main() {
val serialized = Json.stringify(Data.serializer(), Data(1))
val expected = """{"a":1}"""
check(serialized == expected)
}
I think you've mentioned the kotlin.jvm.Transient annotation which is dedicated for the JVM platform and represents Java's transient keyword. This serialization framework is cross-platform and has different semantics, therefore it has its own kotlinx.serialization.Transient annotation, which should be used in @Serializable classes
Ah that's tricky and I assume it leads in a lot of confusion and programming mistakes.
Speaks anything against the serialization plug-in honoring that annotation too?
We could recognize it too, but it would be strange from the semantic point of view
If you decide not to recognize it, I suggest to show a compile-time warning when using the wrong Transient on a Serializable class. This mistake is very easy to make...
I agree with this idea - there should be a warning about using wrong Transient!
IDE warning arrives in the next release
Most helpful comment
If you decide not to recognize it, I suggest to show a compile-time warning when using the wrong
Transienton aSerializableclass. This mistake is very easy to make...