'Swagger generate classes with default constructors on their fields
I want to create some model classes that have nested objects with swagger and I get the following code:
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2022-05-05T12:56:11.358Z[UTC]")public class SomeClass implements Serializable {
private static final long serialVersionUID = 1L;
@JsonProperty("meta")
private MyMeta meta = null;
....
How do I make the field be initialized by its default constructor instead? Something like this below:
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2022-05-05T12:56:11.358Z[UTC]")public class SomeClass implements Serializable {
private static final long serialVersionUID = 1L;
@JsonProperty("meta")
private MyMeta meta = new MyMeta();
....
I know that I can use the build pattern do something like the code below but my class has too many nested objects which will make whoever uses this models having to write multiple extra lines:
new SomeClass().myMeta(new MyMeta())
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
