Skip to content

Commit c158fd6

Browse files
PicazsooCopilot
andauthored
[java][spring][kotlin-spring] Make @JsonInclude/@JsonSetter opt-in to stop overriding global ObjectMapper (#24428)
* feat(json-include): introduce configurable JsonInclude policy for optional non-nullable properties * update samples and documentation * update documentation * feat(json-include): add support for configurable @JsonSetter(nulls) annotations on optional non-nullable properties * docs(migration-guide): update migration guide for Jackson annotations changes in 7.25.0 * Revert "update documentation" This reverts commit ed876b9. * Revert "update samples and documentation" This reverts commit 6408e37. * feat(json-include): enhance manual per-property JSON include policy handling * feat(json-include): refactor JSON include policy handling with utility class * feat(json-include): update JSON include policy constants to use VendorExtension and CodegenConstants * refactor(json-include): replace constants with CodegenConstants in JSON include policy handling * feat(json-include): add @JsonSetter(nulls = Nulls.SKIP) for fields with Lombok setters * feat(json-include): add options for generating @JsonInclude and @JsonSetter annotations * feat(json-include): introduce JsonIncludePolicy and TriStateBoolean for improved JSON annotation handling * update samples * update samples * add whitespace to trigger cicd * Revert "add whitespace to trigger cicd" This reverts commit 3da24e0. * feat(json-include): refactor JSON annotation handling with JsonAnnotationPolicyUtils * update samples * Decouple JsonSetter nulls mode from openApiNullable for optional non-nullable fields Add optionalNonNullPropertyJsonSetterNulls option (SKIP/FAIL) and the per-property x-jackson-json-setter-nulls vendor extension (SKIP/FAIL/NONE) to the spring and kotlin-spring generators, mirroring the JsonInclude mechanism. When unset, behavior is byte-identical to today (openApiNullable-derived default), so this is fully backward compatible. Setting them enables previously-unreachable combinations such as openApiNullable=true with SKIP. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address review: guard test idx, fix setter-nulls NPE on null option, clarify migration note Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * update samples * updated samples * updated docs --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a3868f7 commit c158fd6

712 files changed

Lines changed: 3586 additions & 955 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/configs/kotlin-spring-boot-3-no-response-entity.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
79
documentationProvider: none
810
annotationLibrary: none
911
useSwaggerUI: "false"

bin/configs/kotlin-spring-boot-3.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
9+
optionalNonNullPropertyJsonInclude: "NONE"
710
documentationProvider: none
811
annotationLibrary: none
912
useSwaggerUI: "false"

bin/configs/kotlin-spring-boot-4.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
79
documentationProvider: none
810
annotationLibrary: none
911
useSwaggerUI: "false"

bin/configs/kotlin-spring-boot-additionalproperties.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ library: spring-boot
44
inputSpec: samples/server/petstore/kotlin-springboot-additionalproperties/src/main/resources/openapi.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
79
documentationProvider: none
810
annotationLibrary: none
911
useSwaggerUI: "false"

bin/configs/kotlin-spring-boot-bigdecimal-default.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ outputDir: samples/server/petstore/kotlin-springboot-bigdecimal-default
33
library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_14584_bigdecimal_default.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
6+
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"

bin/configs/kotlin-spring-boot-delegate-nodefaults.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
79
documentationProvider: none
810
annotationLibrary: swagger2
911
useSwaggerUI: "true"

bin/configs/kotlin-spring-boot-delegate.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
79
documentationProvider: springdoc
810
annotationLibrary: swagger2
911
useSwaggerUI: "true"

bin/configs/kotlin-spring-boot-include-http-request-context-delegate.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/petstore-with-x-kotlin-implements.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
79
documentationProvider: none
810
annotationLibrary: swagger1
911
useSwaggerUI: false

bin/configs/kotlin-spring-boot-integer-enum.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/issue19244_integer_enum.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
79
interfaceOnly: "true"
810
skipDefaultInterface: "true"
911
useTags: "true"

bin/configs/kotlin-spring-boot-modelMutable.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
55
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
66
additionalProperties:
7+
generateJsonIncludeAnnotations: "true"
8+
generateJsonSetterNullsAnnotations: "true"
9+
optionalNonNullPropertyJsonInclude: "NON_DEFAULT"
710
documentationProvider: springdoc
811
annotationLibrary: swagger2
912
useSwaggerUI: "true"

0 commit comments

Comments
 (0)