From b185920887f219c88abbe466fc5f4af6b464893c Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 20 Feb 2023 16:54:28 +0200 Subject: [PATCH] Support UUID serialization in REST Client multipart bodies Fixes: #31298 --- .../client/reactive/runtime/RestClientBase.java | 16 ++++++++++++++++ .../io/quarkus/it/rest/client/MultipartBody.java | 5 +++++ .../it/rest/client/MultipartClientResource.java | 2 ++ .../it/rest/client/MultipartResourceTest.java | 3 ++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/extensions/resteasy-reactive/jaxrs-client-reactive/runtime/src/main/java/io/quarkus/jaxrs/client/reactive/runtime/RestClientBase.java b/extensions/resteasy-reactive/jaxrs-client-reactive/runtime/src/main/java/io/quarkus/jaxrs/client/reactive/runtime/RestClientBase.java index 8f456e298c5f8..c7f70ad6d0854 100644 --- a/extensions/resteasy-reactive/jaxrs-client-reactive/runtime/src/main/java/io/quarkus/jaxrs/client/reactive/runtime/RestClientBase.java +++ b/extensions/resteasy-reactive/jaxrs-client-reactive/runtime/src/main/java/io/quarkus/jaxrs/client/reactive/runtime/RestClientBase.java @@ -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; @@ -101,6 +102,18 @@ public String toString(Boolean value) { return value == null ? null : value.toString(); } }; + + private static final ParamConverter 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 paramConverterProviders; private final Map, ParamConverterProvider> providerForClass = new ConcurrentHashMap<>(); @@ -197,6 +210,9 @@ public ParamConverter getConverter(Class rawType, Type genericType, An if (rawType == boolean.class || rawType == Boolean.class) { return (ParamConverter) BOOLEAN_CONVERTER; } + if (rawType == UUID.class) { + return (ParamConverter) UUID_CONVERTER; + } return null; } diff --git a/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartBody.java b/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartBody.java index 0a9205b9cd237..9a23a05737c63 100644 --- a/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartBody.java +++ b/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartBody.java @@ -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; @@ -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; } diff --git a/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartClientResource.java b/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartClientResource.java index cdda2dddf51e3..cb731e3738468 100644 --- a/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartClientResource.java +++ b/integration-tests/rest-client/src/main/java/io/quarkus/it/rest/client/MultipartClientResource.java @@ -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; @@ -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); } } diff --git a/integration-tests/rest-client/src/test/java/io/quarkus/it/rest/client/MultipartResourceTest.java b/integration-tests/rest-client/src/test/java/io/quarkus/it/rest/client/MultipartResourceTest.java index 93e395becdea4..97a9b73994318 100644 --- a/integration-tests/rest-client/src/test/java/io/quarkus/it/rest/client/MultipartResourceTest.java +++ b/integration-tests/rest-client/src/test/java/io/quarkus/it/rest/client/MultipartResourceTest.java @@ -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")