Ask a Question

Spring code gen [Server] not formatting dates properly

Occasional Visitor

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:


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)

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



hi @goodale , swaggerhub uses the open source codegen, please raise your issue there : 


Every swaggerhub deployment we try to pick up the newest codegen version, so if it's fixed in the open source the fix will come to swaggerhub.

Showing results for 
Search instead for 
Did you mean: