From 76fcc81bc61342ed85f7a8a0c325e58162ff24e8 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Wed, 8 Apr 2009 04:47:54 +0000 Subject: [PATCH] New method to return string representation of typeDescriptor --- .../core/convert/TypeDescriptor.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 0d686c3832..f01863014e 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 -- GitLab