Author: hardy.ferentschik
Date: 2009-06-09 10:27:55 -0400 (Tue, 09 Jun 2009)
New Revision: 16724
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java
Log:
Improved handling of array types.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-06-09
14:27:01 UTC (rev 16723)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-06-09
14:27:55 UTC (rev 16724)
@@ -19,8 +19,8 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
-import java.lang.reflect.Array;
import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -30,6 +30,8 @@
import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
+import com.googlecode.jtype.TypeUtils;
+
import org.hibernate.validation.util.ReflectionHelper;
/**
@@ -150,8 +152,8 @@
}
default: {
t = ReflectionHelper.typeOf( member );
- if ( t instanceof Class && ((Class) t).isArray()) {
- t = Array.class;
+ if ( t instanceof Class && ((Class) t).isPrimitive()) {
+ t = ReflectionHelper.boxedTyp( t );
}
}
}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java 2009-06-09
14:27:01 UTC (rev 16723)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java 2009-06-09
14:27:55 UTC (rev 16724)
@@ -18,7 +18,6 @@
package org.hibernate.validation.util;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -29,7 +28,9 @@
import javax.validation.ConstraintValidator;
import javax.validation.ValidationException;
+import com.googlecode.jtype.TypeUtils;
+
/**
* Helper methods around <code>ConstraintValidator</code> types.
*
@@ -70,7 +71,7 @@
throw new ValidationException( "Null is an invalid type for a constraint
validator." );
}
else if ( validatorType instanceof GenericArrayType ) {
- validatorType = Array.class;
+ validatorType = TypeUtils.getArrayType( TypeUtils.getComponentType( validatorType )
);
}
while ( resolvedTypes.containsKey( validatorType ) ) {
@@ -87,7 +88,9 @@
else if ( type instanceof Class ) {
Class clazz = ( Class ) type;
final Type returnedType = resolveTypeForClassAndHierarchy( resolvedTypes, clazz );
- if ( returnedType != null) return returnedType;
+ if ( returnedType != null ) {
+ return returnedType;
+ }
}
else if ( type instanceof ParameterizedType ) {
ParameterizedType paramType = ( ParameterizedType ) type;
@@ -109,7 +112,9 @@
}
else {
Type returnedType = resolveTypeForClassAndHierarchy( resolvedTypes, rawType );
- if ( returnedType != null) return returnedType;
+ if ( returnedType != null ) {
+ return returnedType;
+ }
}
}
//else we don't care I think