|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2011 the original author or authors. |
|
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -13,6 +13,7 @@
@@ -13,6 +13,7 @@
|
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
package org.springframework.core.convert; |
|
|
|
|
|
|
|
|
|
import java.lang.annotation.Annotation; |
|
|
|
|
@ -59,6 +60,7 @@ public class TypeDescriptor {
@@ -59,6 +60,7 @@ public class TypeDescriptor {
|
|
|
|
|
typeDescriptorCache.put(String.class, new TypeDescriptor(String.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Class<?> type; |
|
|
|
|
|
|
|
|
|
private final TypeDescriptor elementTypeDescriptor; |
|
|
|
|
@ -69,6 +71,7 @@ public class TypeDescriptor {
@@ -69,6 +71,7 @@ public class TypeDescriptor {
|
|
|
|
|
|
|
|
|
|
private final Annotation[] annotations; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new type descriptor from a {@link MethodParameter}. |
|
|
|
|
* Use this constructor when a source or target conversion point is a constructor parameter, method parameter, or method return value. |
|
|
|
|
@ -96,6 +99,7 @@ public class TypeDescriptor {
@@ -96,6 +99,7 @@ public class TypeDescriptor {
|
|
|
|
|
this(new BeanPropertyDescriptor(property)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new type descriptor from the given type. |
|
|
|
|
* Use this to instruct the conversion system to convert an object to a specific target type, when no type location such as a method parameter or field is available to provide additional conversion context. |
|
|
|
|
@ -207,6 +211,7 @@ public class TypeDescriptor {
@@ -207,6 +211,7 @@ public class TypeDescriptor {
|
|
|
|
|
return (source != null ? valueOf(source.getClass()) : null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The type of the backing class, method parameter, field, or property described by this TypeDescriptor. |
|
|
|
|
* Returns primitive types as-is. |
|
|
|
|
@ -477,6 +482,7 @@ public class TypeDescriptor {
@@ -477,6 +482,7 @@ public class TypeDescriptor {
|
|
|
|
|
|
|
|
|
|
private TypeDescriptor(Class<?> type, TypeDescriptor elementTypeDescriptor, TypeDescriptor mapKeyTypeDescriptor, |
|
|
|
|
TypeDescriptor mapValueTypeDescriptor, Annotation[] annotations) { |
|
|
|
|
|
|
|
|
|
this.type = type; |
|
|
|
|
this.elementTypeDescriptor = elementTypeDescriptor; |
|
|
|
|
this.mapKeyTypeDescriptor = mapKeyTypeDescriptor; |
|
|
|
|
@ -538,15 +544,25 @@ public class TypeDescriptor {
@@ -538,15 +544,25 @@ public class TypeDescriptor {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
TypeDescriptor other = (TypeDescriptor) obj; |
|
|
|
|
boolean annotatedTypeEquals = ObjectUtils.nullSafeEquals(getType(), other.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), other.getAnnotations()); |
|
|
|
|
if (!annotatedTypeEquals) { |
|
|
|
|
if (!ObjectUtils.nullSafeEquals(getType(), other.getType())) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
Annotation[] ann = getAnnotations(); |
|
|
|
|
Annotation[] otherAnn = other.getAnnotations(); |
|
|
|
|
if (ann.length != otherAnn.length) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < ann.length; i++) { |
|
|
|
|
if (!ann[i].annotationType().equals(otherAnn[i].annotationType())) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (isCollection() || isArray()) { |
|
|
|
|
return ObjectUtils.nullSafeEquals(getElementTypeDescriptor(), other.getElementTypeDescriptor()); |
|
|
|
|
} |
|
|
|
|
else if (isMap()) { |
|
|
|
|
return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) && ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor()); |
|
|
|
|
return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) && |
|
|
|
|
ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor()); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return true; |
|
|
|
|
|