Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we generate @JsonFormat on model variable using swagger-generater?

I have a variable in yml file

startDate:
 type:string
 format:date

I'm using swagger-generater to generate java code from yml.

It's generating a startDate variable as below

@JsonProperty("startDate")
private LocalDate startDate = null; 

But I need as below

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

Can someone help me on this?

like image 821
Sairam Kukadala Avatar asked Feb 14 '26 05:02

Sairam Kukadala


1 Answers

You can add x-field-extra-annotation to add anything annotation you need. Document is here: https://openapi-generator.tech/docs/generators/java

startDate:
 type:string
 format:date
 x-field-extra-annotation: '@com.fasterxml.jackson.annotation.JsonFormat(shape = com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")'

Then generated model class will have annotation JsonFormat

like image 107
sendon1982 Avatar answered Feb 16 '26 19:02

sendon1982



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!