[BUG][KOTLIN] No JsonAdapter for LocalDateTime in Moshi serializer
Created by: toXel
Description
date-time
fields can't be parsed from a generated Kotlin client with default configuration. It fails with this exception:
java.lang.IllegalArgumentException: Platform class java.time.LocalDateTime annotated [] requires explicit JsonAdapter to be registered
The reason for it is that in Serializer.kt.mustache Moshi only gets a JsonAdapter for the java.util.Date
type but not for java.time.LocalDateTime
(or org.threeten.bp.LocalDateTime
when ThreeTen is used).
openapi-generator version
v3.3.1
Command line used for generation
generate -g kotlin -i https://petstore.swagger.io/v2/swagger.yaml -o swaggerClientTest
Steps to reproduce
It can be reproduced with the petstore swagger spec.
- Generate Kotlin client with the command above.
- Write a simple test like this:
@Test
fun getOrderById() {
val order = StoreApi().getOrderById(1)
assertNotNull(order)
}
- It will fail with the respective exception.
Suggest a fix/enhancement
A workaround is to implement a JsonAdapter
for the respective type and add it to Moshi in the generated Serializer
class. Maybe this can be integrated in the generator.