[Java] [Spring-client] Exclude discriminator from nullable annotation (#21981)

* Exclude the discriminator from getting a nullable-annotation

* Update samples
This commit is contained in:
Mattias Sehlstedt 2025-09-19 08:50:58 +02:00 committed by GitHub
parent ac3c37095d
commit 73c8728343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 39 additions and 24 deletions

View File

@ -67,7 +67,12 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
{{#gson}}
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
{{/gson}}
{{^isDiscriminator}}
{{>nullable_var_annotations}}{{! prevent indent}}
{{/isDiscriminator}}
{{#isDiscriminator}}
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
{{/isDiscriminator}}
{{#vendorExtensions.x-field-extra-annotation}}
{{{vendorExtensions.x-field-extra-annotation}}}
{{/vendorExtensions.x-field-extra-annotation}}

View File

@ -67,7 +67,12 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{#gson}}
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
{{/gson}}
{{^isDiscriminator}}
{{>nullable_var_annotations}}{{! prevent indent}}
{{/isDiscriminator}}
{{#isDiscriminator}}
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
{{/isDiscriminator}}
{{#vendorExtensions.x-field-extra-annotation}}
{{{vendorExtensions.x-field-extra-annotation}}}
{{/vendorExtensions.x-field-extra-annotation}}

View File

@ -67,7 +67,12 @@ public {{>sealed}}class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#v
{{#gson}}
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
{{/gson}}
{{^isDiscriminator}}
{{>nullable_var_annotations}}{{! prevent indent}}
{{/isDiscriminator}}
{{#isDiscriminator}}
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
{{/isDiscriminator}}
{{#vendorExtensions.x-field-extra-annotation}}
{{{vendorExtensions.x-field-extra-annotation}}}
{{/vendorExtensions.x-field-extra-annotation}}

View File

@ -41,7 +41,7 @@ public final class Apple implements Fruit {
private Integer seeds;
public static final String JSON_PROPERTY_FRUIT_TYPE = "fruitType";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
private FruitType fruitType;
public Apple() {

View File

@ -41,7 +41,7 @@ public final class Banana implements Fruit {
private Integer length;
public static final String JSON_PROPERTY_FRUIT_TYPE = "fruitType";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
private FruitType fruitType;
public Banana() {

View File

@ -70,7 +70,7 @@ public class Entity {
protected String atBaseType;
public static final String JSON_PROPERTY_AT_TYPE = "@type";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String atType;
public Entity() {

View File

@ -76,7 +76,7 @@ public class EntityRef {
protected String atBaseType;
public static final String JSON_PROPERTY_AT_TYPE = "@type";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String atType;
public EntityRef() {

View File

@ -48,7 +48,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@jakarta.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -84,7 +84,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@jakarta.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -47,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@jakarta.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -83,7 +83,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@jakarta.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -47,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@jakarta.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -83,7 +83,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@jakarta.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -47,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@jakarta.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -83,7 +83,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@jakarta.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -55,7 +55,7 @@ import io.github.threetenjaxb.core.*;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@XmlElement(name = "className")
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -94,7 +94,7 @@ public class ParentWithNullable {
public static final String JSON_PROPERTY_TYPE = "type";
@XmlElement(name = "type")
@javax.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -47,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -83,7 +83,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@javax.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -47,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@jakarta.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -83,7 +83,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@jakarta.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -48,7 +48,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -84,7 +84,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@javax.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -47,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -83,7 +83,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@javax.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";

View File

@ -47,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
public class Animal {
public static final String JSON_PROPERTY_CLASS_NAME = "className";
@javax.annotation.Nonnull
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected String className;
public static final String JSON_PROPERTY_COLOR = "color";

View File

@ -83,7 +83,7 @@ public class ParentWithNullable {
}
public static final String JSON_PROPERTY_TYPE = "type";
@javax.annotation.Nullable
// The discriminator does not have Nullability-annotation since it is added during serialization by the @JsonTypeName annotation
protected TypeEnum type;
public static final String JSON_PROPERTY_NULLABLE_PROPERTY = "nullableProperty";