From 71201e1a4310990762ed9a0a74114c3aac4905c5 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 13 Oct 2016 13:23:22 -0400 Subject: [PATCH] Relax generic type detection for ResponseEntity Before this change the getHttpEntityType method in HttpEntityMethodProcessor raised an ISE if the generic type cannot be detected. That made sense for resolving a controller method argument where the target body type is crucial. However for a return value the generic type should not be required since we either have an actual body or no body at all in which case it doesn't even matter. This change relaxes the checks and defaults to Object.class for the ResponseEntity generic type on the return value side. Issue: SPR-14799 --- .../method/annotation/HttpEntityMethodProcessor.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java index 214980f14d5..98ec1ebdfd7 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java @@ -121,6 +121,10 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro ServletServerHttpRequest inputMessage = createInputMessage(webRequest); Type paramType = getHttpEntityType(parameter); + if (paramType == null) { + throw new IllegalArgumentException("HttpEntity parameter '" + parameter.getParameterName() + + "' in method " + parameter.getMethod() + " is not parameterized"); + } Object body = readWithMessageConverters(webRequest, parameter, paramType); if (RequestEntity.class == parameter.getParameterType()) { @@ -146,8 +150,9 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro else if (parameterType instanceof Class) { return Object.class; } - throw new IllegalArgumentException("HttpEntity parameter '" + parameter.getParameterName() + - "' in method " + parameter.getMethod() + " is not parameterized"); + else { + return null; + } } @Override @@ -243,6 +248,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro } else { Type type = getHttpEntityType(returnType); + type = (type != null ? type : Object.class); return ResolvableType.forMethodParameter(returnType, type).resolve(Object.class); } }