Exclude Part and MultipartFile from nested constructor binding
Closes gh-31669
This commit is contained in:
@@ -24,6 +24,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.Part;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -120,6 +121,13 @@ public class ServletRequestDataBinder extends WebDataBinder {
|
||||
return new ServletRequestValueResolver(request, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldConstructArgument(MethodParameter param) {
|
||||
Class<?> type = param.nestedIfOptional().getNestedParameterType();
|
||||
return (super.shouldConstructArgument(param) &&
|
||||
!MultipartFile.class.isAssignableFrom(type) && !Part.class.isAssignableFrom(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the parameters of the given request to this binder's target,
|
||||
* also binding multipart files in case of a multipart request.
|
||||
|
||||
@@ -18,8 +18,10 @@ package org.springframework.web.bind.support;
|
||||
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.Part;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -30,6 +32,7 @@ import org.springframework.web.bind.ServletRequestDataBinder;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartRequest;
|
||||
import org.springframework.web.multipart.support.StandardServletPartUtils;
|
||||
|
||||
@@ -118,6 +121,12 @@ public class WebRequestDataBinder extends WebDataBinder {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldConstructArgument(MethodParameter param) {
|
||||
Class<?> type = param.nestedIfOptional().getNestedParameterType();
|
||||
return (super.shouldConstructArgument(param) &&
|
||||
!MultipartFile.class.isAssignableFrom(type) && !Part.class.isAssignableFrom(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the parameters of the given request to this binder's target,
|
||||
|
||||
Reference in New Issue
Block a user