diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java index 7c60b603e53d7..020a3458cb1d3 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java @@ -134,8 +134,7 @@ public void testAnnotationFreeSubresource() throws Exception { Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Assertions.assertEquals(response.readEntity(String.class), "got"); Assertions.assertNotNull(response.getHeaderString("Content-Type")); - Assertions.assertNotNull(response.getHeaderString("Content-Type")); - Assertions.assertEquals(MediaType.TEXT_PLAIN_TYPE.toString(), + Assertions.assertEquals("text/plain;charset=UTF-8", response.getHeaderString("Content-Type")); } { diff --git a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java index c09283af77e5b..74d30f8121baa 100644 --- a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java +++ b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java @@ -54,6 +54,7 @@ import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; +import java.nio.charset.StandardCharsets; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; @@ -490,6 +491,7 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf String[] produces = extractProducesConsumesValues(currentMethodInfo.annotation(PRODUCES), classProduces); produces = applyDefaultProduces(produces, nonAsyncReturnType); + produces = addDefaultCharsets(produces); String sseElementType = classSseElementType; AnnotationInstance sseElementTypeAnnotation = currentMethodInfo.annotation(REST_SSE_ELEMENT_TYPE); @@ -626,6 +628,22 @@ private String[] applyDefaultProduces(String[] produces, Type nonAsyncReturnType return applyAdditionalDefaults(nonAsyncReturnType); } + // see https://github.com/quarkusio/quarkus/issues/19535 + private String[] addDefaultCharsets(String[] produces) { + if ((produces == null) || (produces.length == 0)) { + return produces; + } + List result = new ArrayList<>(produces.length); + for (String p : produces) { + if (p.equals(MediaType.TEXT_PLAIN)) { + result.add(MediaType.TEXT_PLAIN + ";charset=" + StandardCharsets.UTF_8.name()); + } else { + result.add(p); + } + } + return result.toArray(EMPTY_STRING_ARRAY); + } + protected String[] applyAdditionalDefaults(Type nonAsyncReturnType) { // FIXME: primitives if (STRING.equals(nonAsyncReturnType.name())) @@ -724,7 +742,7 @@ private static String[] extractProducesConsumesValues(AnnotationInstance annotat result.add(t.trim()); } } - return result.toArray(new String[0]); + return result.toArray(EMPTY_STRING_ARRAY); } else { return originalStrings; }