Closed ghajba closed 5 years ago
Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.
Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.
@schmidt-sebastian is this something we ought to support?
We currently have no plans to support serialization of these date types. Please use java.util.Date
in the meantime.
Related to #75
Here is 2024 now and JSR 310 (java.time) was shipped in Java 8 from 10 years ago. Users would be very happy if we don't need to deal with the conversion problem anymore.
Currently I copy paste this snippet to my project every time, just to transforming the data classes for using Firestore.
fun Any.toFirestoreObject() = this.javaClass.declaredFields.associate {
it.isAccessible = true
val transform = converters[it.type.kotlin] ?: { it }
it.name to transform(it.get(this))
}
val converters = hashMapOf<KClass<*>, (Any) -> Any>(
LocalDate::class to { Timestamp.valueOf((it as LocalDate).atStartOfDay()) },
LocalDateTime::class to { Timestamp.valueOf(it as LocalDateTime) }
)
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
When I try to serialize a
LocalDate
I get the following exception.The cause is, that
LocalDate
overrides thejava.time.chrono.ChronoLocalDate.getChronology()
method which returns ajava.time.chrono.Chronology
. The override returnsjava.time.chrono.IsoChronology
which is an implementation of the original return type.Question: how can such overrides be addressed in the future that such classes (available in core Java or other libraries without access) can be serialized? If we can figure this out, I am happy to create a PR with the implementation.