Skip to content

Commit 166ebc5

Browse files
authored
[Java][okhttp-gson] validateJsonElement does not validate enum values (#16865)
* validate enum properties in validateJsonElement * regenerate samples * add test for enum validation in okhttp-gson models
1 parent 291ce35 commit 166ebc5

54 files changed

Lines changed: 761 additions & 1 deletion

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/utils/test_file_list.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java"
1111
sha256: db505f7801fef62c13a08a8e9ca1fc4c5c947ab46b46f12943139d353feacf17
1212
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java"
13-
sha256: 3371236d615e7fb79ed87d00c9fc486c31c379195a658781ac9440f0e3228d62
13+
sha256: 6db714e9744c150c8982c3cb18e4f37a9c1ecd8f72f6d58943986e781ab4a344
1414
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java"
1515
sha256: 0d64cdc11809a7b5b952ccdad2bd91bd0045b3894d6fabf3e368fa0be12b8217
1616
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{{#jackson}}
2+
import com.fasterxml.jackson.annotation.JsonCreator;
3+
import com.fasterxml.jackson.annotation.JsonValue;
4+
{{/jackson}}
5+
{{#gson}}
6+
import java.io.IOException;
7+
import com.google.gson.TypeAdapter;
8+
import com.google.gson.JsonElement;
9+
import com.google.gson.annotations.JsonAdapter;
10+
import com.google.gson.stream.JsonReader;
11+
import com.google.gson.stream.JsonWriter;
12+
{{/gson}}
13+
14+
/**
15+
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
16+
*/
17+
{{#gson}}
18+
@JsonAdapter({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Adapter.class)
19+
{{/gson}}
20+
{{#jsonb}}
21+
@JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
22+
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
23+
{{/jsonb}}
24+
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
25+
{{#allowableValues}}{{#enumVars}}
26+
{{#enumDescription}}
27+
/**
28+
* {{.}}
29+
*/
30+
{{/enumDescription}}
31+
{{#withXml}}
32+
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
33+
{{/withXml}}
34+
{{{name}}}({{{value}}}){{^-last}},
35+
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
36+
37+
private {{{dataType}}} value;
38+
39+
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
40+
this.value = value;
41+
}
42+
43+
{{#jackson}}
44+
@JsonValue
45+
{{/jackson}}
46+
public {{{dataType}}} getValue() {
47+
return value;
48+
}
49+
50+
@Override
51+
public String toString() {
52+
return String.valueOf(value);
53+
}
54+
55+
{{#jackson}}
56+
@JsonCreator
57+
{{/jackson}}
58+
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
59+
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
60+
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
61+
return b;
62+
}
63+
}
64+
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
65+
}
66+
{{#gson}}
67+
68+
public static class Adapter extends TypeAdapter<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> {
69+
@Override
70+
public void write(final JsonWriter jsonWriter, final {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} enumeration) throws IOException {
71+
jsonWriter.value(enumeration.getValue());
72+
}
73+
74+
@Override
75+
public {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
76+
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = jsonReader.{{#isNumber}}nextString(){{/isNumber}}{{#isInteger}}nextInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}}{{/isNumber}};
77+
return {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue({{#isNumber}}new BigDecimal({{/isNumber}}value{{#isNumber}}){{/isNumber}});
78+
}
79+
}
80+
81+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
82+
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = jsonElement.{{#isNumber}}getAsString(){{/isNumber}}{{#isInteger}}getAsInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}getAs{{{dataType}}}(){{/isInteger}}{{/isNumber}};
83+
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue({{#isNumber}}new BigDecimal({{/isNumber}}value{{#isNumber}}){{/isNumber}});
84+
}
85+
{{/gson}}
86+
{{#jsonb}}
87+
88+
public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
89+
@Override
90+
public {{datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
91+
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
92+
if (String.valueOf(b.value).equals(parser.getString())) {
93+
return b;
94+
}
95+
}
96+
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");{{/useNullForUnknownEnumValue}}
97+
}
98+
}
99+
100+
public static final class Serializer implements JsonbSerializer<{{datatypeWithEnum}}> {
101+
@Override
102+
public void serialize({{datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
103+
generator.write(obj.value);
104+
}
105+
}
106+
{{/jsonb}}
107+
{{#supportUrlQuery}}
108+
109+
/**
110+
* Convert the instance into URL query string.
111+
*
112+
* @param prefix prefix of the query string
113+
* @return URL query string
114+
*/
115+
public String toUrlQueryString(String prefix) {
116+
if (prefix == null) {
117+
prefix = "";
118+
}
119+
120+
return String.format("%s=%s", prefix, this.toString());
121+
}
122+
{{/supportUrlQuery}}
123+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
3+
*/
4+
{{#gson}}
5+
@JsonAdapter({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.Adapter.class)
6+
{{/gson}}
7+
{{#jsonb}}
8+
@JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
9+
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
10+
{{/jsonb}}
11+
{{#withXml}}
12+
@XmlType(name="{{datatypeWithEnum}}")
13+
@XmlEnum({{dataType}}.class)
14+
{{/withXml}}
15+
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
16+
{{#allowableValues}}
17+
{{#enumVars}}
18+
{{#enumDescription}}
19+
/**
20+
* {{.}}
21+
*/
22+
{{/enumDescription}}
23+
{{#withXml}}
24+
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
25+
{{/withXml}}
26+
{{{name}}}({{{value}}}){{^-last}},
27+
{{/-last}}{{#-last}};{{/-last}}
28+
{{/enumVars}}
29+
{{/allowableValues}}
30+
31+
private {{{dataType}}} value;
32+
33+
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{dataType}}} value) {
34+
this.value = value;
35+
}
36+
37+
{{#jackson}}
38+
@JsonValue
39+
{{/jackson}}
40+
public {{{dataType}}} getValue() {
41+
return value;
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return String.valueOf(value);
47+
}
48+
49+
{{#jackson}}
50+
@JsonCreator
51+
{{/jackson}}
52+
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
53+
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
54+
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
55+
return b;
56+
}
57+
}
58+
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
59+
}
60+
{{#gson}}
61+
62+
public static class Adapter extends TypeAdapter<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}> {
63+
@Override
64+
public void write(final JsonWriter jsonWriter, final {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} enumeration) throws IOException {
65+
jsonWriter.value(enumeration.getValue());
66+
}
67+
68+
@Override
69+
public {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
70+
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = {{#isFloat}}(float){{/isFloat}} jsonReader.{{#isNumber}}nextString(){{/isNumber}}{{#isInteger}}nextInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}{{#isFloat}}nextDouble{{/isFloat}}{{^isFloat}}next{{{dataType}}}{{/isFloat}}(){{/isInteger}}{{/isNumber}};
71+
return {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue({{#isNumber}}new BigDecimal({{/isNumber}}value{{#isNumber}}){{/isNumber}});
72+
}
73+
}
74+
75+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
76+
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = jsonElement.{{#isNumber}}getAsString(){{/isNumber}}{{#isInteger}}getAsInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}getAs{{{dataType}}}(){{/isInteger}}{{/isNumber}};
77+
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.fromValue({{#isNumber}}new BigDecimal({{/isNumber}}value{{#isNumber}}){{/isNumber}});
78+
}
79+
{{/gson}}
80+
{{#jsonb}}
81+
public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
82+
@Override
83+
public {{datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
84+
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
85+
if (String.valueOf(b.value).equals(parser.getString())) {
86+
return b;
87+
}
88+
}
89+
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");{{/useNullForUnknownEnumValue}}
90+
}
91+
}
92+
93+
public static final class Serializer implements JsonbSerializer<{{datatypeWithEnum}}> {
94+
@Override
95+
public void serialize({{datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
96+
generator.write(obj.value);
97+
}
98+
}
99+
{{/jsonb}}
100+
}

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,30 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
552552
}
553553
{{/required}}
554554
{{/isModel}}
555+
{{#isEnum}}
556+
{{#required}}
557+
// validate the required field `{{{baseName}}}`
558+
{{{datatypeWithEnum}}}.validateJsonElement(jsonObj.get("{{{baseName}}}"));
559+
{{/required}}
560+
{{^required}}
561+
// validate the optional field `{{{baseName}}}`
562+
if (jsonObj.get("{{{baseName}}}") != null && !jsonObj.get("{{{baseName}}}").isJsonNull()) {
563+
{{{datatypeWithEnum}}}.validateJsonElement(jsonObj.get("{{{baseName}}}"));
564+
}
565+
{{/required}}
566+
{{/isEnum}}
567+
{{#isEnumRef}}
568+
{{#required}}
569+
// validate the required field `{{{baseName}}}`
570+
{{{dataType}}}.validateJsonElement(jsonObj.get("{{{baseName}}}"));
571+
{{/required}}
572+
{{^required}}
573+
// validate the optional field `{{{baseName}}}`
574+
if (jsonObj.get("{{{baseName}}}") != null && !jsonObj.get("{{{baseName}}}").isJsonNull()) {
575+
{{{dataType}}}.validateJsonElement(jsonObj.get("{{{baseName}}}"));
576+
}
577+
{{/required}}
578+
{{/isEnumRef}}
555579
{{/isContainer}}
556580
{{/vars}}
557581
{{/discriminator}}

samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/DefaultValue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public ArrayStringEnumDefaultEnum read(final JsonReader jsonReader) throws IOExc
106106
return ArrayStringEnumDefaultEnum.fromValue(value);
107107
}
108108
}
109+
110+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
111+
String value = jsonElement.getAsString();
112+
ArrayStringEnumDefaultEnum.fromValue(value);
113+
}
109114
}
110115

111116
public static final String SERIALIZED_NAME_ARRAY_STRING_ENUM_DEFAULT = "array_string_enum_default";

samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pet.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public StatusEnum read(final JsonReader jsonReader) throws IOException {
122122
return StatusEnum.fromValue(value);
123123
}
124124
}
125+
126+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
127+
String value = jsonElement.getAsString();
128+
StatusEnum.fromValue(value);
129+
}
125130
}
126131

127132
public static final String SERIALIZED_NAME_STATUS = "status";
@@ -399,6 +404,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
399404
if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) {
400405
throw new IllegalArgumentException(String.format("Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString()));
401406
}
407+
// validate the optional field `status`
408+
if (jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) {
409+
StatusEnum.validateJsonElement(jsonObj.get("status"));
410+
}
402411
}
403412

404413
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {

samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Query.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public OutcomesEnum read(final JsonReader jsonReader) throws IOException {
104104
return OutcomesEnum.fromValue(value);
105105
}
106106
}
107+
108+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
109+
String value = jsonElement.getAsString();
110+
OutcomesEnum.fromValue(value);
111+
}
107112
}
108113

109114
public static final String SERIALIZED_NAME_OUTCOMES = "outcomes";

samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/StringEnumRef.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import com.google.gson.TypeAdapter;
21+
import com.google.gson.JsonElement;
2122
import com.google.gson.annotations.JsonAdapter;
2223
import com.google.gson.stream.JsonReader;
2324
import com.google.gson.stream.JsonWriter;
@@ -70,5 +71,10 @@ public StringEnumRef read(final JsonReader jsonReader) throws IOException {
7071
return StringEnumRef.fromValue(value);
7172
}
7273
}
74+
75+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
76+
String value = jsonElement.getAsString();
77+
StringEnumRef.fromValue(value);
78+
}
7379
}
7480

samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SomeObj.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public TypeEnum read(final JsonReader jsonReader) throws IOException {
9797
return TypeEnum.fromValue(value);
9898
}
9999
}
100+
101+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
102+
String value = jsonElement.getAsString();
103+
TypeEnum.fromValue(value);
104+
}
100105
}
101106

102107
public static final String SERIALIZED_NAME_$_TYPE = "$_type";
@@ -314,6 +319,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
314319
if ((jsonObj.get("$_type") != null && !jsonObj.get("$_type").isJsonNull()) && !jsonObj.get("$_type").isJsonPrimitive()) {
315320
throw new IllegalArgumentException(String.format("Expected the field `$_type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("$_type").toString()));
316321
}
322+
// validate the optional field `$_type`
323+
if (jsonObj.get("$_type") != null && !jsonObj.get("$_type").isJsonNull()) {
324+
TypeEnum.validateJsonElement(jsonObj.get("$_type"));
325+
}
317326
if ((jsonObj.get("name") != null && !jsonObj.get("name").isJsonNull()) && !jsonObj.get("name").isJsonPrimitive()) {
318327
throw new IllegalArgumentException(String.format("Expected the field `name` to be a primitive type in the JSON string but got `%s`", jsonObj.get("name").toString()));
319328
}

samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/Order.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ public StatusEnum read(final JsonReader jsonReader) throws IOException {
115115
return StatusEnum.fromValue(value);
116116
}
117117
}
118+
119+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
120+
String value = jsonElement.getAsString();
121+
StatusEnum.fromValue(value);
122+
}
118123
}
119124

120125
public static final String SERIALIZED_NAME_STATUS = "status";
@@ -382,6 +387,10 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
382387
if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) {
383388
throw new IllegalArgumentException(String.format("Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString()));
384389
}
390+
// validate the optional field `status`
391+
if (jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) {
392+
StatusEnum.validateJsonElement(jsonObj.get("status"));
393+
}
385394
}
386395

387396
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {

0 commit comments

Comments
 (0)