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

Transient not working #470

Closed
PaulWoitaschek opened this issue May 27, 2019 · 6 comments
Closed

Transient not working #470

PaulWoitaschek opened this issue May 27, 2019 · 6 comments
Labels

Comments

@PaulWoitaschek
Copy link
Contributor

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)
}
  • Kotlin version: [e.g. 1.3.31]
  • Library version: [e.g. 0.11.1] ]
@sandwwraith
Copy link
Member

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

@PaulWoitaschek
Copy link
Contributor Author

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?

@sandwwraith
Copy link
Member

We could recognize it too, but it would be strange from the semantic point of view

@natanfudge
Copy link

natanfudge commented Sep 6, 2019

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...

@StragaSevera
Copy link

I agree with this idea - there should be a warning about using wrong Transient!

@qwwdfsad
Copy link
Collaborator

IDE warning arrives in the next release

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

No branches or pull requests

5 participants