Skip to content

[java][resteasy] fixes serialize list of files and deserialize file #17813

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -495,7 +496,14 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
MultipartFormDataOutput multipart = new MultipartFormDataOutput();
//MultiPart multiPart = new MultiPart();
for (Entry<String, Object> param: formParams.entrySet()) {
if (param.getValue() instanceof File) {
if( param.getValue() instanceof List && !( ( List ) param.getValue() ).isEmpty()
&& ( ( List ) param.getValue() ).get( 0 ) instanceof File ) {
@SuppressWarnings( "unchecked" )
List<File> files = ( List<File> ) param.getValue();
for( File file : files ) {
multipart.addFormData(param.getKey(),new FileInputStream(file),MediaType.APPLICATION_OCTET_STREAM_TYPE, file.getName());
}
} else if (param.getValue() instanceof File) {
File file = (File) param.getValue();
try {
multipart.addFormData(param.getKey(),new FileInputStream(file),MediaType.APPLICATION_OCTET_STREAM_TYPE, file.getName());
Expand Down Expand Up @@ -534,10 +542,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
return null;
}

if ("byte[]".equals(returnType.toString())) {
if (returnType.getRawType().equals(byte[].class)) {
// Handle binary response (byte array).
return (T) response.readEntity(byte[].class);
} else if (returnType.equals(File.class)) {
} else if (returnType.getRawType().equals(File.class)) {
// Handle file downloading.
@SuppressWarnings("unchecked")
T file = (T) downloadFileFromResponse(response);
Expand All @@ -563,7 +571,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
public File downloadFileFromResponse(Response response) throws ApiException {
try {
File file = prepareDownloadFile(response);
Files.copy(response.readEntity(InputStream.class), file.toPath());
Files.copy(response.readEntity(InputStream.class), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
return file;
} catch (IOException e) {
throw new ApiException(e);
Expand Down