Skip to content

fix: honor required fields in jackson @JsonProperty annotations #21062

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* If the field is required, always include it, even if it is null.
* Else use custom behaviour, IOW use whatever is defined on the object mapper
}}
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
@JsonProperty(value = JSON_PROPERTY_{{nameInSnakeCase}}, required = {{required}})
@JsonInclude({{#isMap}}{{#items.isNullable}}content = JsonInclude.Include.ALWAYS, {{/items.isNullable}}{{/isMap}}value = JsonInclude.Include.{{#required}}ALWAYS{{/required}}{{^required}}USE_DEFAULTS{{/required}})
{{#withXml}}
@JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{#jsonb}}@JsonbCreator{{/jsonb}}{{#jackson}}@JsonCreator{{/jackson}}
public {{classname}}(
{{#readOnlyVars}}
{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nullable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nullable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(value = JSON_PROPERTY_{{nameInSnakeCase}}, required = {{required}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
{{/readOnlyVars}}
) {
this();
Expand All @@ -123,7 +123,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
/**
* Constructor with all args parameters
*/
public {{classname}}({{#vendorExtensions.x-java-all-args-constructor-vars}}{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nullable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-java-all-args-constructor-vars}}) {
public {{classname}}({{#vendorExtensions.x-java-all-args-constructor-vars}}{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nullable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(value = JSON_PROPERTY_{{nameInSnakeCase}}, required = {{required}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-java-all-args-constructor-vars}}) {
{{#parent}}
super({{#parentVars}}{{name}}{{^-last}}, {{/-last}}{{/parentVars}});
{{/parent}}
Expand Down Expand Up @@ -252,7 +252,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
return {{name}};
}
{{/vendorExtensions.x-is-jackson-optional-nullable}}{{#vendorExtensions.x-is-jackson-optional-nullable}}
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
@JsonProperty(value = JSON_PROPERTY_{{nameInSnakeCase}}, required = {{required}})
{{#isReadOnly}}private{{/isReadOnly}}{{^isReadOnly}}public{{/isReadOnly}} void {{setter}}_JsonNullable(JsonNullable<{{{datatypeWithEnum}}}> {{name}}) {
{{! For getters/setters that have name differing from attribute name, we must include setter (albeit private) for jackson to be able to set the attribute}}
this.{{name}} = {{name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2099,10 +2099,10 @@ public void testDeprecatedPropertyJersey3() {
TestUtils.assertFileContains(
output.resolve("src/main/java/org/openapitools/client/model/BigDog.java"),
"@Deprecated\n public BigDog declawed(@jakarta.annotation.Nullable Boolean declawed) {", // deprecated builder method
"@Deprecated\n @jakarta.annotation.Nullable\n @JsonProperty(JSON_PROPERTY_DECLAWED)\n"
"@Deprecated\n @jakarta.annotation.Nullable\n @JsonProperty(value = JSON_PROPERTY_DECLAWED, required = false)\n"
+ " @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)\n\n"
+ " public Boolean getDeclawed() {", // deprecated getter
"@Deprecated\n @JsonProperty(JSON_PROPERTY_DECLAWED)\n"
"@Deprecated\n @JsonProperty(value = JSON_PROPERTY_DECLAWED, required = false)\n"
+ " @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)\n"
+ " public void setDeclawed(@jakarta.annotation.Nullable Boolean declawed) {" // deprecated setter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public Bird size(@javax.annotation.Nullable String size) {
* @return size
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_SIZE)
@JsonProperty(value = JSON_PROPERTY_SIZE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public String getSize() {
return size;
}


@JsonProperty(JSON_PROPERTY_SIZE)
@JsonProperty(value = JSON_PROPERTY_SIZE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSize(@javax.annotation.Nullable String size) {
this.size = size;
Expand All @@ -82,15 +82,15 @@ public Bird color(@javax.annotation.Nullable String color) {
* @return color
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_COLOR)
@JsonProperty(value = JSON_PROPERTY_COLOR, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public String getColor() {
return color;
}


@JsonProperty(JSON_PROPERTY_COLOR)
@JsonProperty(value = JSON_PROPERTY_COLOR, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setColor(@javax.annotation.Nullable String color) {
this.color = color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public Category id(@javax.annotation.Nullable Long id) {
* @return id
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_ID)
@JsonProperty(value = JSON_PROPERTY_ID, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public Long getId() {
return id;
}


@JsonProperty(JSON_PROPERTY_ID)
@JsonProperty(value = JSON_PROPERTY_ID, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setId(@javax.annotation.Nullable Long id) {
this.id = id;
Expand All @@ -82,15 +82,15 @@ public Category name(@javax.annotation.Nullable String name) {
* @return name
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_NAME)
@JsonProperty(value = JSON_PROPERTY_NAME, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public String getName() {
return name;
}


@JsonProperty(JSON_PROPERTY_NAME)
@JsonProperty(value = JSON_PROPERTY_NAME, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setName(@javax.annotation.Nullable String name) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public DataQuery suffix(@javax.annotation.Nullable String suffix) {
* @return suffix
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_SUFFIX)
@JsonProperty(value = JSON_PROPERTY_SUFFIX, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public String getSuffix() {
return suffix;
}


@JsonProperty(JSON_PROPERTY_SUFFIX)
@JsonProperty(value = JSON_PROPERTY_SUFFIX, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSuffix(@javax.annotation.Nullable String suffix) {
this.suffix = suffix;
Expand All @@ -93,15 +93,15 @@ public DataQuery text(@javax.annotation.Nullable String text) {
* @return text
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_TEXT)
@JsonProperty(value = JSON_PROPERTY_TEXT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public String getText() {
return text;
}


@JsonProperty(JSON_PROPERTY_TEXT)
@JsonProperty(value = JSON_PROPERTY_TEXT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setText(@javax.annotation.Nullable String text) {
this.text = text;
Expand All @@ -118,15 +118,15 @@ public DataQuery date(@javax.annotation.Nullable OffsetDateTime date) {
* @return date
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_DATE)
@JsonProperty(value = JSON_PROPERTY_DATE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public OffsetDateTime getDate() {
return date;
}


@JsonProperty(JSON_PROPERTY_DATE)
@JsonProperty(value = JSON_PROPERTY_DATE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setDate(@javax.annotation.Nullable OffsetDateTime date) {
this.date = date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ public DefaultValue addArrayStringEnumRefDefaultItem(StringEnumRef arrayStringEn
* @return arrayStringEnumRefDefault
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_ARRAY_STRING_ENUM_REF_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_ENUM_REF_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public List<StringEnumRef> getArrayStringEnumRefDefault() {
return arrayStringEnumRefDefault;
}


@JsonProperty(JSON_PROPERTY_ARRAY_STRING_ENUM_REF_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_ENUM_REF_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setArrayStringEnumRefDefault(@javax.annotation.Nullable List<StringEnumRef> arrayStringEnumRefDefault) {
this.arrayStringEnumRefDefault = arrayStringEnumRefDefault;
Expand All @@ -173,15 +173,15 @@ public DefaultValue addArrayStringEnumDefaultItem(ArrayStringEnumDefaultEnum arr
* @return arrayStringEnumDefault
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_ARRAY_STRING_ENUM_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_ENUM_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public List<ArrayStringEnumDefaultEnum> getArrayStringEnumDefault() {
return arrayStringEnumDefault;
}


@JsonProperty(JSON_PROPERTY_ARRAY_STRING_ENUM_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_ENUM_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setArrayStringEnumDefault(@javax.annotation.Nullable List<ArrayStringEnumDefaultEnum> arrayStringEnumDefault) {
this.arrayStringEnumDefault = arrayStringEnumDefault;
Expand All @@ -206,15 +206,15 @@ public DefaultValue addArrayStringDefaultItem(String arrayStringDefaultItem) {
* @return arrayStringDefault
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_ARRAY_STRING_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public List<String> getArrayStringDefault() {
return arrayStringDefault;
}


@JsonProperty(JSON_PROPERTY_ARRAY_STRING_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setArrayStringDefault(@javax.annotation.Nullable List<String> arrayStringDefault) {
this.arrayStringDefault = arrayStringDefault;
Expand All @@ -239,15 +239,15 @@ public DefaultValue addArrayIntegerDefaultItem(Integer arrayIntegerDefaultItem)
* @return arrayIntegerDefault
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_ARRAY_INTEGER_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_INTEGER_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public List<Integer> getArrayIntegerDefault() {
return arrayIntegerDefault;
}


@JsonProperty(JSON_PROPERTY_ARRAY_INTEGER_DEFAULT)
@JsonProperty(value = JSON_PROPERTY_ARRAY_INTEGER_DEFAULT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setArrayIntegerDefault(@javax.annotation.Nullable List<Integer> arrayIntegerDefault) {
this.arrayIntegerDefault = arrayIntegerDefault;
Expand All @@ -272,15 +272,15 @@ public DefaultValue addArrayStringItem(String arrayStringItem) {
* @return arrayString
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_ARRAY_STRING)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public List<String> getArrayString() {
return arrayString;
}


@JsonProperty(JSON_PROPERTY_ARRAY_STRING)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setArrayString(@javax.annotation.Nullable List<String> arrayString) {
this.arrayString = arrayString;
Expand Down Expand Up @@ -315,14 +315,14 @@ public List<String> getArrayStringNullable() {
return arrayStringNullable.orElse(null);
}

@JsonProperty(JSON_PROPERTY_ARRAY_STRING_NULLABLE)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_NULLABLE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public JsonNullable<List<String>> getArrayStringNullable_JsonNullable() {
return arrayStringNullable;
}

@JsonProperty(JSON_PROPERTY_ARRAY_STRING_NULLABLE)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_NULLABLE, required = false)
public void setArrayStringNullable_JsonNullable(JsonNullable<List<String>> arrayStringNullable) {
this.arrayStringNullable = arrayStringNullable;
}
Expand Down Expand Up @@ -360,14 +360,14 @@ public List<String> getArrayStringExtensionNullable() {
return arrayStringExtensionNullable.orElse(null);
}

@JsonProperty(JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public JsonNullable<List<String>> getArrayStringExtensionNullable_JsonNullable() {
return arrayStringExtensionNullable;
}

@JsonProperty(JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE)
@JsonProperty(value = JSON_PROPERTY_ARRAY_STRING_EXTENSION_NULLABLE, required = false)
public void setArrayStringExtensionNullable_JsonNullable(JsonNullable<List<String>> arrayStringExtensionNullable) {
this.arrayStringExtensionNullable = arrayStringExtensionNullable;
}
Expand All @@ -393,14 +393,14 @@ public String getStringNullable() {
return stringNullable.orElse(null);
}

@JsonProperty(JSON_PROPERTY_STRING_NULLABLE)
@JsonProperty(value = JSON_PROPERTY_STRING_NULLABLE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public JsonNullable<String> getStringNullable_JsonNullable() {
return stringNullable;
}

@JsonProperty(JSON_PROPERTY_STRING_NULLABLE)
@JsonProperty(value = JSON_PROPERTY_STRING_NULLABLE, required = false)
public void setStringNullable_JsonNullable(JsonNullable<String> stringNullable) {
this.stringNullable = stringNullable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public NumberPropertiesOnly number(@javax.annotation.Nullable BigDecimal number)
* @return number
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_NUMBER)
@JsonProperty(value = JSON_PROPERTY_NUMBER, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public BigDecimal getNumber() {
return number;
}


@JsonProperty(JSON_PROPERTY_NUMBER)
@JsonProperty(value = JSON_PROPERTY_NUMBER, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setNumber(@javax.annotation.Nullable BigDecimal number) {
this.number = number;
Expand All @@ -88,15 +88,15 @@ public NumberPropertiesOnly _float(@javax.annotation.Nullable Float _float) {
* @return _float
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_FLOAT)
@JsonProperty(value = JSON_PROPERTY_FLOAT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public Float getFloat() {
return _float;
}


@JsonProperty(JSON_PROPERTY_FLOAT)
@JsonProperty(value = JSON_PROPERTY_FLOAT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setFloat(@javax.annotation.Nullable Float _float) {
this._float = _float;
Expand All @@ -115,15 +115,15 @@ public NumberPropertiesOnly _double(@javax.annotation.Nullable Double _double) {
* @return _double
*/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_DOUBLE)
@JsonProperty(value = JSON_PROPERTY_DOUBLE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public Double getDouble() {
return _double;
}


@JsonProperty(JSON_PROPERTY_DOUBLE)
@JsonProperty(value = JSON_PROPERTY_DOUBLE, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setDouble(@javax.annotation.Nullable Double _double) {
this._double = _double;
Expand Down
Loading
Loading