kotlinx-datetime
kotlinx-datetime copied to clipboard
Implement java.io.Serializable for some of the classes
Implement java.io.Serializable for
- Instant
- LocalDate
- LocalTime
- LocalDateTime
- UtcOffset
TimeZone is not Serializable because its behavior is system-dependent. We can make it java.io.Serializable later if there is demand.
We are using string representations instead of relying on Java's entities being java.io.Serializable so that we have more freedom to change our implementation later.
Fixes #143
Can you please merge this commit if possible? @ilya-g
I don't understand the idea. Do you mean that LocalTime should be Externalizable?
From the docs (https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/io/Externalizable.html):
When an Externalizable object is reconstructed, an instance is created using the public no-arg constructor
But we don't have public no-arg constructors. I guess we could do something like class LocalTime { @PublishedApi internal constructor() }, which would make it a public constructor for the JVM, and trick Kotlin somehow to avoid initializing val value: java.time.LocalTime in that constructor, but is it worth it to make such intrusive changes just to support Java serialization?
A very necessary implementation on Android to be able to pass LocalDate/LocalDateTime objects between screens
@akhbulatov, it's not "necessary", just convenient: see https://github.com/Kotlin/kotlinx-datetime/issues/143#issuecomment-975380754
Do you have an estimate when this will get merged? It's a pretty huge inconvenience for us to wrap Instant because we want to export an SDK and the wrapping shouldn't be exposed to our users. It seems to be impossible without writing huge amounts of boilerplate.
Do you mean https://github.com/JetBrains/kotlin/blob/3be0aa15f714726e4872c09b35f789652c46876d/libraries/stdlib/jvm/src/kotlin/collections/builders/ListBuilder.kt#L674? Ok, I think I got the idea, thanks. This does look better than reflection.
It's not important to me who does this.
I think it's good to go, but can't approve a pull request that I myself opened.