Skip to content

Commit da21a99

Browse files
committed
[Java] Fix content for enum with restclient (#19973)
1 parent b65cd5d commit da21a99

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,13 +1732,16 @@ public class ApiClient {
17321732
RequestBody requestBody;
17331733
if (obj instanceof String) {
17341734
requestBody = RequestBody.create((String) obj, MediaType.parse("text/plain"));
1735-
} else if (obj == null){
1736-
requestBody = RequestBody.create(obj, MediaType.parse("application/json"));
1737-
} else if (obj.getClass().getEnumConstants() != null) {
1738-
requestBody = RequestBody.create(obj.toString(), MediaType.parse("text/plain"));
17391735
} else {
1740-
requestBody = RequestBody.create(JSON.serialize(obj), MediaType.parse("application/json"));
1736+
String content;
1737+
if (obj != null) {
1738+
content = JSON.serialize(obj);
1739+
} else {
1740+
content = null;
1741+
}
1742+
requestBody = RequestBody.create(content, MediaType.parse("application/json"));
17411743
}
1744+
17421745
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"");
17431746
mpBuilder.addPart(partHeaders, requestBody);
17441747
}

0 commit comments

Comments
 (0)