Skip to content
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

Support UUID serialization in REST Client multipart bodies #31300

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
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 @@ -5,6 +5,7 @@
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

Expand Down Expand Up @@ -101,6 +102,18 @@ public String toString(Boolean value) {
return value == null ? null : value.toString();
}
};

private static final ParamConverter<UUID> UUID_CONVERTER = new ParamConverter<>() {
@Override
public UUID fromString(String value) {
return value == null ? null : UUID.fromString(value);
}

@Override
public String toString(UUID value) {
return value == null ? null : value.toString();
}
};
private final List<ParamConverterProvider> paramConverterProviders;
private final Map<Class<?>, ParamConverterProvider> providerForClass = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -197,6 +210,9 @@ public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, An
if (rawType == boolean.class || rawType == Boolean.class) {
return (ParamConverter<T>) BOOLEAN_CONVERTER;
}
if (rawType == UUID.class) {
return (ParamConverter<T>) UUID_CONVERTER;
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.it.rest.client;

import java.io.InputStream;
import java.util.UUID;

import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -16,4 +17,8 @@ public class MultipartBody {
@FormParam("fileName")
@PartType(MediaType.TEXT_PLAIN)
public String fileName;

@FormParam("uuid")
@PartType(MediaType.TEXT_PLAIN)
public UUID uuid;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
Expand All @@ -27,6 +28,7 @@ public String sendFile() throws Exception {
MultipartBody body = new MultipartBody();
body.fileName = "greeting.txt";
body.file = new ByteArrayInputStream("HELLO WORLD".getBytes(StandardCharsets.UTF_8));
body.uuid = UUID.randomUUID();
return service.sendMultipartData(body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public void testMultipartDataIsSent() {
.body(containsString("Content-Disposition: form-data; name=\"file\""),
containsString("HELLO WORLD"),
containsString("Content-Disposition: form-data; name=\"fileName\""),
containsString("greeting.txt"));
containsString("greeting.txt"),
containsString("Content-Disposition: form-data; name=\"uuid\""));

given()
.when().get("/q/metrics")
Expand Down