[QUESTION] How to Deserialize a UTC DateTime String using kotlinx-datetime

I have a datetime string I need to deserialize:

this is my string with utc datetime format:

“2000-01-01T00:00:00.000Z”

in my model I have the fields in the serializeable object declared as LocalDate and LocalDateTime:

@Serializable data class MyObject( val date: LocalDate? = null val utcDateTime: LocalDateTime? = null ) 

Deserialzation of LocalDate works fine. But I think the timezone indicator at the end of the string confuses the deserializer.

What I got from the documentation adding the timezone to a localdatetime should work by calling .toInstant

val tz = TimeZone.of("Europe/Berlin") val local = LocalDate(2020, Month.JULY, 25) .atTime(15, 45) val instant = local.toInstant(tz) // 2020-07-25T13:45:00Z 

But declaring the DateTime object as Instant doesnt provide the day month year time etc anymore.

what can I do to deserialize this?

submitted by /u/johnzzz123
[link] [comments]