I am using the OpenAPI java generator [1] with library:resttemplate, dateLibrary:java8 in a spring project to generate a client from a spec.
For a property in the spec:
targetDate:
type: string
format: date
the following code is generated:
public static final String JSON_PROPERTY_TARGET_DATE = "targetDate";
private LocalDate targetDate;
@javax.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_TARGET_DATE)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public LocalDate getTargetDate() {
return targetDate;
}
@JsonProperty(JSON_PROPERTY_TARGET_DATE)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setTargetDate(LocalDate targetDate) {
this.targetDate = targetDate;
}
I would expect this field to be serialized to a full date e.g. "2023-01-01" as promised by the spec: https://spec.openapis.org/oas/v3.0.0#data-types. However it is in fact serialized to an array: [2023,1,1]
.
Similarly another property
otherDate:
type: string
format: date-time
is serialized to seconds since epoch, instead of full-time. (I assume this is a bug in the generator)
I cannot add any annotations since the code is generated. How can I still ensure that the date is properly serialized?
[1] openapi-generator-maven-plugin 6.3.0