Forum Discussion

goodale's avatar
goodale
Occasional Visitor
2 years ago
Solved

Spring code gen [Server] not formatting dates properly

I'm using the codegen tool in swaggerhub to generate Spring server-side code stubs.  I have a openapi field with the following structure:

 

birthdate:
type: string
format: date
pattern: "YYYY-MM-DD"
example: "1995-01-01"


i've set the swagger export configuration to use Java 11 JSR384 and use Jackson.    However, the generated code is not formatting the output properly.  Instead of getting a date value in the format of "YYYY-MM-DD"  i am getting a long/integer in the json output.    I've also confirmed the generated source code is using java.util.Date.

Am i missing a crucial configuration step? I can work around the issue by adding the following annotation to the generated code.  But that is an issue since it means I am altering auto-generated code (e.g. brittle/risky)

@JsonProperty("birthdate")
@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date birthdate = null;