]> source.dussan.org Git - vaadin-framework.git/commitdiff
Bump hibernate-validator from 4.3.2.Final to 5.3.5.Final (#12083)
authorTatu Lund <tatu@vaadin.com>
Tue, 25 Aug 2020 15:37:20 +0000 (18:37 +0300)
committerGitHub <noreply@github.com>
Tue, 25 Aug 2020 15:37:20 +0000 (18:37 +0300)
Hibernate Validator 5+ requires
- Validation API 2+
- explicit Expression Language dependency

compatibility-server/src/main/java/com/vaadin/v7/data/validator/BeanValidator.java
pom.xml
server/src/main/java/com/vaadin/data/validator/BeanValidator.java
server/src/test/java/com/vaadin/data/validator/BeanValidatorTest.java

index 48bb16753fe3c157601eac4388d119275b9e8513..49ba4bd69ddecd991ab78c5b8978554b6cc4557f 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Set;
 import javax.validation.ConstraintViolation;
 import javax.validation.MessageInterpolator.Context;
 import javax.validation.Validation;
+import javax.validation.ValidationException;
 import javax.validation.ValidatorFactory;
 import javax.validation.metadata.ConstraintDescriptor;
 
@@ -67,6 +68,7 @@ public class BeanValidator implements Validator {
     protected static class SimpleContext implements Context, Serializable {
 
         private final Object value;
+        private final ConstraintViolation<?> violation;
         private final ConstraintDescriptor<?> descriptor;
 
         /**
@@ -74,13 +76,20 @@ public class BeanValidator implements Validator {
          *
          * @param value
          *            value being validated
-         * @param descriptor
-         *            ConstraintDescriptor corresponding to the constraint being
+         * @param violation
+         *            ConstraintViolation corresponding to the constraint being
          *            validated
          */
+        public SimpleContext(Object value, ConstraintViolation<?> violation) {
+            this.value = value;
+            this.violation = violation;
+            this.descriptor = violation.getConstraintDescriptor();
+        }
+
         public SimpleContext(Object value, ConstraintDescriptor<?> descriptor) {
             this.value = value;
             this.descriptor = descriptor;
+            this.violation = null;
         }
 
         @Override
@@ -93,6 +102,21 @@ public class BeanValidator implements Validator {
             return value;
         }
 
+        @Override
+        public <T> T unwrap(Class<T> type) {
+            if (violation != null) {
+                return violation.unwrap(type);
+            } else {
+               try {
+                    return type.newInstance();
+                } catch (InstantiationException e) {
+                    throw new ValidationException();
+                } catch (IllegalAccessException e) {
+                    throw new ValidationException();
+                }
+            }
+        }
+
     }
 
     /**
@@ -128,7 +152,7 @@ public class BeanValidator implements Validator {
                         .getMessageInterpolator()
                         .interpolate(violation.getMessageTemplate(),
                                 new SimpleContext(value,
-                                        violation.getConstraintDescriptor()),
+                                        violation),
                                 locale);
                 causes[i] = new InvalidValueException(msg);
                 ++i;
diff --git a/pom.xml b/pom.xml
index b8041e5b16881a960cd7d25b329f7c4d94f823cd..63807b70411d0b14c9ba9a3ca7ead958c2398f48 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
         <vaadin.plugin.version>8.7-SNAPSHOT</vaadin.plugin.version>
 
         <!-- Used in OSGi manifests -->
-        <javax.validation.version>1.0.0.GA</javax.validation.version>
+        <javax.validation.version>2.0.1.Final</javax.validation.version>
         <jsoup.version>1.11.2</jsoup.version>
         <javax.portlet.version>2.0</javax.portlet.version>
         <vaadin.sass.version>0.9.13</vaadin.sass.version>
             <dependency>
                 <groupId>org.hibernate</groupId>
                 <artifactId>hibernate-validator</artifactId>
-                <version>4.3.2.Final</version>
+                <version>5.3.5.Final</version>
             </dependency>
             <dependency>
                 <groupId>org.jsoup</groupId>
             <artifactId>hibernate-validator</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.glassfish</groupId>
+            <artifactId>javax.el</artifactId>
+            <version>3.0.0</version>
+            <scope>test</scope>
+        </dependency>  
     </dependencies>
     <build>
         <pluginManagement>
index 9084e1eed6fa88b2d8d0bdcbbefced477d60fcc4..64b96ed06a46b596f855629e466e9c6578dc09e1 100644 (file)
@@ -69,6 +69,10 @@ public class BeanValidator implements Validator<Object> {
             return violation.getInvalidValue();
         }
 
+        @Override
+        public <T> T unwrap(Class<T> type) {
+            return violation.unwrap(type);
+        }
     }
 
     private String propertyName;
index f595be14bc83260677c8c56557301b4087f271a8..4abe08d24cbb0742b2aa3a24170dc3037050a9af 100644 (file)
@@ -60,8 +60,8 @@ public class BeanValidatorTest extends ValidatorTestBase {
     public void testInvalidDecimalsFailsInFrench() {
         setLocale(Locale.FRENCH);
         BeanValidator v = validator("decimals");
-        assertFails("1234.567", "Valeur numérique hors limite "
-                + "(<3 chiffres>.<2 chiffres> attendus)", v);
+        assertFails("1234.567", "valeur numérique hors limite "
+                + "(<3 chiffres>.<2 chiffres> attendu)", v);
     }
 
     @Test