-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[BUG][KOTLIN] No JsonAdapter for LocalDateTime in Moshi serializer #1271
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
Comments
same for |
I'm hitting this same issue with the Applicable line in generated code looks like this: /* Absolute time when... */
@Json(name = "absolute_time")
val absoluteTime: java.time.OffsetDateTime? = null Applicable lines in "absolute_time": {
"type": "string",
"format": "date-time",
"description": "Absolute time when ..."
} And the exception that moshi is throwing:
|
@jpmeijers did you find out how to use OffsetDateTime with Moshi? I have been trying to write a custom adapter but still getting errors. Thanks |
I'm not 100% sure as it's a while back, but looks like I created a custom adapter: And then added that to the Moshi instance:
|
Thanks for the response! I was able to get it working :) |
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 forjava.time.LocalDateTime
(ororg.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.
Suggest a fix/enhancement
A workaround is to implement a
JsonAdapter
for the respective type and add it to Moshi in the generatedSerializer
class. Maybe this can be integrated in the generator.The text was updated successfully, but these errors were encountered: