diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 0d686c3832e224346f0886e5f0e49f64be5e275a..f01863014e454fe6b38e96b2bcf9bf000add1934 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -25,6 +25,7 @@ import org.springframework.core.GenericCollectionTypeResolver; import org.springframework.core.MethodParameter; import org.springframework.util.Assert; +// TODO doesn't support more than depth of one (eg. Map> or List[]) /** * Type metadata about a bindable target value. * @@ -269,6 +270,33 @@ public class TypeDescriptor { return valueOf(object.getClass()); } } + + /** + * @return a textual representation of the type descriptor (eg. Map) 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