|
|
@ -36,6 +36,7 @@ import org.springframework.core.KotlinDetector;
|
|
|
|
import org.springframework.core.MethodParameter;
|
|
|
|
import org.springframework.core.MethodParameter;
|
|
|
|
import org.springframework.core.ParameterNameDiscoverer;
|
|
|
|
import org.springframework.core.ParameterNameDiscoverer;
|
|
|
|
import org.springframework.core.ResolvableType;
|
|
|
|
import org.springframework.core.ResolvableType;
|
|
|
|
|
|
|
|
import org.springframework.core.convert.ConversionException;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -94,16 +95,30 @@ class ValueObjectBinder implements DataObjectBinder {
|
|
|
|
Annotation[] annotations = parameter.getAnnotations();
|
|
|
|
Annotation[] annotations = parameter.getAnnotations();
|
|
|
|
for (Annotation annotation : annotations) {
|
|
|
|
for (Annotation annotation : annotations) {
|
|
|
|
if (annotation instanceof DefaultValue) {
|
|
|
|
if (annotation instanceof DefaultValue) {
|
|
|
|
DefaultValue defaultValue = (DefaultValue) annotation;
|
|
|
|
String[] defaultValue = ((DefaultValue) annotation).value();
|
|
|
|
if (defaultValue.value().length == 0) {
|
|
|
|
if (defaultValue.length == 0) {
|
|
|
|
return getNewInstanceIfPossible(context, type);
|
|
|
|
return getNewInstanceIfPossible(context, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return context.getConverter().convert(defaultValue.value(), type, annotations);
|
|
|
|
return convertDefaultValue(context.getConverter(), defaultValue, type, annotations);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private <T> T convertDefaultValue(BindConverter converter, String[] defaultValue, ResolvableType type,
|
|
|
|
|
|
|
|
Annotation[] annotations) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return converter.convert(defaultValue, type, annotations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (ConversionException ex) {
|
|
|
|
|
|
|
|
// Try again in case ArrayToObjectConverter is not in play
|
|
|
|
|
|
|
|
if (defaultValue.length == 1) {
|
|
|
|
|
|
|
|
return converter.convert(defaultValue[0], type, annotations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private <T> T getNewInstanceIfPossible(Binder.Context context, ResolvableType type) {
|
|
|
|
private <T> T getNewInstanceIfPossible(Binder.Context context, ResolvableType type) {
|
|
|
|
Class<T> resolved = (Class<T>) type.resolve();
|
|
|
|
Class<T> resolved = (Class<T>) type.resolve();
|
|
|
|