Reputation: 163
I'm using OpenAPI Generator to create a client, but when I trying to make a POST request is serialized the LocalDateTime like a integer array, looks like
{
"startDate": [ 2019, 11, 13, 0, 0 ],
"endDate": [ 2020, 12, 31, 0, 0 ]
}
I'm waiting for this result, parse like a ISO string
{
"startDate": "2019-11-13T00:00",
"endDate": "2020-12-31T00:00"
}
My gradle configuration is this:
dependencies {
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.3'
classpath 'org.openapitools:openapi-generator-gradle-plugin:4.2.3'
}
task generateClientDS(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
inputSpec = "$rootDir/specifications/client-ds.yaml".toString()
outputDir = "$rootDir".toString()
generatorName = 'java'
library = 'resttemplate'
apiPackage = 'com.example.gen.clients.clientds.api'
modelPackage = 'com.example.gen.clients.clientds.dto'
modelNameSuffix = 'DTO'
configOptions = [
hideGenerationTimestamp: 'true',
dateLibrary: 'java8'
]
typeMappings = [
OffsetDateTime: 'java.time.LocalDateTime'
]
}
application.properties
spring.jackson.serialization.write-dates-as-timestamps=false
I've even added it as been but it doesn't work, any idea what is wrong?
Upvotes: 5
Views: 4456
Reputation: 71
I was looking for a solution to the same problem for LocalDate
For me the solution was:
typeMappings = [
LocalDate: "String"
]
Also I found explanation of this behaviour in the tread: https://stackoverflow.com/a/75881743/8725920
This is not a bug, but a conscious decision on the part of the developers. You said you are using the java generator with the resttemplate library. By default, the resttemplate library generates a class called RFC3339DateFormat, and a class called JavaTimeFormatter
Upvotes: 1
Reputation: 124
I get the same error. After a few hours of looking found the answer here. The problem was in my API doc. Try to change it.
startDate:
type: string
format: 'yyyy-mm-dd'
Upvotes: 1