diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index c5eea077c30..66987fb32cd 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -513,15 +513,18 @@ public class TypeDescriptor implements Serializable { } ResolvableType element = (elementTypeDescriptor == null ? null : elementTypeDescriptor.resolvableType); - return new TypeDescriptor(ResolvableType.forClassWithGenerics(collectionType, - element), null, null); + return new TypeDescriptor(ResolvableType.forClassWithGenerics(collectionType, element), null, null); } /** * Create a new type descriptor from a {@link java.util.Map} type. *

Useful for converting to typed Maps. - *

For example, a Map<String, String> could be converted to a Map<Id, EmailAddress> by converting to a targetType built with this method: - * The method call to construct such a TypeDescriptor would look something like: map(Map.class, TypeDescriptor.valueOf(Id.class), TypeDescriptor.valueOf(EmailAddress.class)); + *

For example, a Map<String, String> could be converted to a Map<Id, EmailAddress> + * by converting to a targetType built with this method: + * The method call to construct such a TypeDescriptor would look something like: + *

+	 * map(Map.class, TypeDescriptor.valueOf(Id.class), TypeDescriptor.valueOf(EmailAddress.class));
+	 * 
* @param mapType the map type, which must implement {@link Map} * @param keyTypeDescriptor a descriptor for the map's key type, used to convert map keys * @param valueTypeDescriptor the map's value type, used to convert map values @@ -538,18 +541,19 @@ public class TypeDescriptor implements Serializable { /** * Create a new type descriptor as an array of the specified type. - *

For example to create a {@code Map[]} use - * {@code TypeDescriptor.array(TypeDescriptor.map(Map.class, TypeDescriptor.value(String.class), TypeDescriptor.value(String.class)))}. + *

For example to create a {@code Map[]} use: + *

+	 * TypeDescriptor.array(TypeDescriptor.map(Map.class, TypeDescriptor.value(String.class), TypeDescriptor.value(String.class)));
+	 * 
* @param elementTypeDescriptor the {@link TypeDescriptor} of the array element or {@code null} * @return an array {@link TypeDescriptor} or {@code null} if {@code elementTypeDescriptor} is {@code null} * @since 3.2.1 */ public static TypeDescriptor array(TypeDescriptor elementTypeDescriptor) { - if(elementTypeDescriptor == null) { + if (elementTypeDescriptor == null) { return null; } - return new TypeDescriptor( - ResolvableType.forArrayComponent(elementTypeDescriptor.resolvableType), + return new TypeDescriptor(ResolvableType.forArrayComponent(elementTypeDescriptor.resolvableType), null, elementTypeDescriptor.getAnnotations()); } @@ -572,13 +576,13 @@ public class TypeDescriptor implements Serializable { * @return the nested type descriptor at the specified nesting level, or null * if it could not be obtained * @throws IllegalArgumentException if the nesting level of the input - * {@link MethodParameter} argument is not 1 - * @throws IllegalArgumentException if the types up to the specified nesting - * level are not of collection, array, or map types + * {@link MethodParameter} argument is not 1, or if the types up to the + * specified nesting level are not of collection, array, or map types */ public static TypeDescriptor nested(MethodParameter methodParameter, int nestingLevel) { if (methodParameter.getNestingLevel() != 1) { - throw new IllegalArgumentException("methodParameter nesting level must be 1: use the nestingLevel parameter to specify the desired nestingLevel for nested type traversal"); + throw new IllegalArgumentException("methodParameter nesting level must be 1: " + + "use the nestingLevel parameter to specify the desired nestingLevel for nested type traversal"); } return nested(new TypeDescriptor(methodParameter), nestingLevel); } @@ -634,8 +638,10 @@ public class TypeDescriptor implements Serializable { /** * Create a new type descriptor for an object. - *

Use this factory method to introspect a source object before asking the conversion system to convert it to some another type. - *

If the provided object is null, returns null, else calls {@link #valueOf(Class)} to build a TypeDescriptor from the object's class. + *

Use this factory method to introspect a source object before asking the + * conversion system to convert it to some another type. + *

If the provided object is null, returns null, else calls {@link #valueOf(Class)} + * to build a TypeDescriptor from the object's class. * @param source the source object * @return the type descriptor */ @@ -649,7 +655,8 @@ public class TypeDescriptor implements Serializable { if (Object.class.equals(nested.getType())) { // could be a collection type but we don't know about its element type, // so let's just assume there is an element type of type Object - } else { + } + else { nested = nested.getNested(2); } } 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 8d127ba1b10..d5284d62687 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 @@ -61,6 +61,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro super(messageConverters, contentNegotiationManager); } + @Override public boolean supportsParameter(MethodParameter parameter) { Class parameterType = parameter.getParameterType(); @@ -69,13 +70,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro @Override public boolean supportsReturnType(MethodParameter returnType) { - Class parameterType = returnType.getParameterType(); - return HttpEntity.class.isAssignableFrom(parameterType) || ResponseEntity.class.isAssignableFrom(parameterType); + return HttpEntity.class.isAssignableFrom(returnType.getParameterType()); } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws IOException, HttpMediaTypeNotSupportedException { @@ -92,19 +91,15 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro if (type.getActualTypeArguments().length == 1) { return type.getActualTypeArguments()[0]; } - throw new IllegalArgumentException("HttpEntity parameter (" - + parameter.getParameterName() + ") in method " + parameter.getMethod() - + " is not parameterized or has more than one parameter"); + throw new IllegalArgumentException("HttpEntity parameter (" + parameter.getParameterName() + + ") in method " + parameter.getMethod() + " is not parameterized or has more than one parameter"); } @Override - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { mavContainer.setRequestHandled(true); - if (returnValue == null) { return; } @@ -128,7 +123,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro writeWithMessageConverters(body, returnType, inputMessage, outputMessage); } else { - // flush headers to the HttpServletResponse + // Flush headers to the HttpServletResponse outputMessage.getBody(); } }