Skip to content

Commit 411e311

Browse files
committed
[Java] Fix content for enum in addPartToMultiPartBuilder ([#19973](#19973))
1 parent 81cdc82 commit 411e311

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,16 +1732,13 @@ 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"));
17351739
} else {
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"));
1740+
requestBody = RequestBody.create(JSON.serialize(obj), MediaType.parse("application/json"));
17431741
}
1744-
17451742
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"");
17461743
mpBuilder.addPart(partHeaders, requestBody);
17471744
}

0 commit comments

Comments
 (0)