-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[Spring] constructor improvements (@JsonProperty, JSpecify support) #22809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7729070
a5424f2
a8fd5e0
de36fc5
cc2d8a6
82d6263
a9d0883
5f989c9
acd89a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| generatorName: spring | ||
| outputDir: samples/openapi3/server/petstore/springboot-jspecify | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
| additionalProperties: | ||
| groupId: org.openapitools.openapi.jspecify | ||
| documentationProvider: springdoc | ||
| artifactId: springboot | ||
| snapshotVersion: "true" | ||
| useSpringBoot3: true | ||
| useBeanValidation: true | ||
| hideGenerationTimestamp: "true" | ||
| generateConstructorWithAllArgs: true | ||
| additionalModelTypeAnnotations: '@org.jspecify.annotations.NullMarked' | ||
| importMappings: | ||
| Nullable: org.jspecify.annotations.Nullable |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,8 @@ public TypeHolderExample() { | |
| /** | ||
| * Constructor with only required parameters | ||
| */ | ||
| public TypeHolderExample(String stringItem, BigDecimal numberItem, Float floatItem, Integer integerItem, Boolean boolItem, List<Integer> arrayItem) { | ||
| @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: @JsonCreator constructor can override the default non-null list with null when array_item is missing, violating the @NotNull contract for arrayItem. Prompt for AI agents |
||
| public TypeHolderExample(@JsonProperty("string_item") String stringItem, @JsonProperty("number_item") BigDecimal numberItem, @JsonProperty("float_item") Float floatItem, @JsonProperty("integer_item") Integer integerItem, @JsonProperty("bool_item") Boolean boolItem, @JsonProperty("array_item") List<Integer> arrayItem) { | ||
| this.stringItem = stringItem; | ||
| this.numberItem = numberItem; | ||
| this.floatItem = floatItem; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,8 @@ public Banana() { | |
| /** | ||
| * Constructor with only required parameters | ||
| */ | ||
| public Banana(Integer length) { | ||
| @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
| public Banana(@JsonProperty("length") Integer length) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: @JsonCreator constructor lacks a fruitType parameter, so fruitType remains null due to self-assignment, violating required discriminator field. Prompt for AI agents |
||
| this.length = length; | ||
| this.fruitType = fruitType; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,8 @@ public TypeHolderExample() { | |
| /** | ||
| * Constructor with only required parameters | ||
| */ | ||
| public TypeHolderExample(String stringItem, BigDecimal numberItem, Float floatItem, Integer integerItem, Boolean boolItem, List<Integer> arrayItem) { | ||
| @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) | ||
| public TypeHolderExample(@JsonProperty("string_item") String stringItem, @JsonProperty("number_item") BigDecimal numberItem, @JsonProperty("float_item") Float floatItem, @JsonProperty("integer_item") Integer integerItem, @JsonProperty("bool_item") Boolean boolItem, @JsonProperty("array_item") List<Integer> arrayItem) { | ||
| this.stringItem = stringItem; | ||
| this.numberItem = numberItem; | ||
| this.floatItem = floatItem; | ||
|
Comment on lines
+49
to
53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: @JsonCreator constructor overwrites the default Prompt for AI agents |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: @JsonCreator property-based constructor will receive null for missing JSON properties, so this change overwrites default field initializers with nulls and can violate @NotNull/default-value expectations.
Prompt for AI agents