diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java index 4a8353b41c..f4fcedb344 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java @@ -789,7 +789,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen for (Object o : messageConverter.getSupportedMediaTypes()) { MediaType supportedMediaType = (MediaType) o; for (MediaType acceptedMediaType : acceptedMediaTypes) { - if (supportedMediaType.includes(acceptedMediaType)) { + if (acceptedMediaType.includes(supportedMediaType)) { messageConverter.write(returnValue, outputMessage); this.responseArgumentUsed = true; return; diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java index 75b9e67bad..6fbf82713b 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java @@ -987,6 +987,20 @@ public class ServletAnnotationControllerTests { assertEquals(406, response.getStatus()); } + @Test + public void responseBodyWildCardMediaType() throws ServletException, IOException { + initServlet(RequestBodyController.class); + + MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something"); + String requestBody = "Hello World"; + request.setContent(requestBody.getBytes("UTF-8")); + request.addHeader("Content-Type", "text/plain; charset=utf-8"); + request.addHeader("Accept", "*/*"); + MockHttpServletResponse response = new MockHttpServletResponse(); + servlet.service(request, response); + assertEquals(requestBody, response.getContentAsString()); + } + @Test public void unsupportedRequestBody() throws ServletException, IOException { initServlet(RequestBodyController.class);