New method to return string representation of typeDescriptor
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@943 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
f383dc9fcf
commit
1d639f091c
|
|
@ -25,6 +25,7 @@ import org.springframework.core.GenericCollectionTypeResolver;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
// TODO doesn't support more than depth of one (eg. Map<String,List<Foo>> or List<String>[])
|
||||||
/**
|
/**
|
||||||
* Type metadata about a bindable target value.
|
* Type metadata about a bindable target value.
|
||||||
*
|
*
|
||||||
|
|
@ -269,6 +270,33 @@ public class TypeDescriptor {
|
||||||
return valueOf(object.getClass());
|
return valueOf(object.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a textual representation of the type descriptor (eg. Map<String,Foo>) for use in messages
|
||||||
|
*/
|
||||||
|
public String asString() {
|
||||||
|
StringBuffer stringValue = new StringBuffer();
|
||||||
|
if (isArray()) {
|
||||||
|
// TODO should properly handle multi dimensional arrays
|
||||||
|
stringValue.append(getArrayComponentType().getName()).append("[]");
|
||||||
|
} else {
|
||||||
|
stringValue.append(getType().getName());
|
||||||
|
if (isCollection()) {
|
||||||
|
Class<?> collectionType = getCollectionElementType();
|
||||||
|
if (collectionType!=null) {
|
||||||
|
stringValue.append("<").append(collectionType.getName()).append(">");
|
||||||
|
}
|
||||||
|
} else if (isMap()) {
|
||||||
|
Class<?> keyType = getMapKeyType();
|
||||||
|
Class<?> valType = getMapValueType();
|
||||||
|
if (keyType!=null && valType!=null) {
|
||||||
|
stringValue.append("<").append(keyType.getName()).append(",");
|
||||||
|
stringValue.append(valType).append(">");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stringValue.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal helpers
|
// internal helpers
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue