Skip to content

Commit

Permalink
Support UUID serialization in REST Client multipart bodies
Browse files Browse the repository at this point in the history
Fixes: quarkusio#31298
(cherry picked from commit b185920)
  • Loading branch information
geoand authored and gsmet committed Feb 22, 2023
1 parent 6d2601c commit d57bf97
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
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 javax.ws.rs.FormParam;
import javax.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 javax.inject.Inject;
import javax.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

0 comments on commit d57bf97

Please sign in to comment.