Ask a Question

Spring code gen [Server] not formatting dates properly

SOLVED
goodale
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:

 

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;

 

1 REPLY 1
KJans
Staff

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

 

https://github.com/swagger-api/swagger-codegen/issues 

 

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.

cancel
Showing results for 
Search instead for 
Did you mean: