Empty string check after conversion in AbstractNamedValueArgumentResolver

Closes gh-33794
This commit is contained in:
rstoyanchev
2024-11-06 14:10:45 +00:00
parent 59ec871e76
commit d4719493bd
2 changed files with 12 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ValueConstants;
/**
@@ -191,11 +192,15 @@ public abstract class AbstractNamedValueArgumentResolver implements HttpServiceA
}
if (this.conversionService != null && !(value instanceof String)) {
Object beforeValue = value;
parameter = parameter.nestedIfOptional();
Class<?> type = parameter.getNestedParameterType();
value = (type != Object.class && !type.isArray() ?
this.conversionService.convert(value, new TypeDescriptor(parameter), STRING_TARGET_TYPE) :
this.conversionService.convert(value, String.class));
if (!StringUtils.hasText((String) value) && !required && beforeValue == null) {
value = null;
}
}
if (value == null) {