{"id":6950,"date":"2013-01-14T19:00:12","date_gmt":"2013-01-14T17:00:12","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=6950"},"modified":"2013-06-11T10:14:22","modified_gmt":"2013-06-11T07:14:22","slug":"integrating-bean-validation-with-jax-rs-in-java-ee-6","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html","title":{"rendered":"Integrating Bean Validation with JAX-RS in Java EE 6"},"content":{"rendered":"<p>JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by constraints in the form of annotations placed on a field, method, or class of a JavaBeans component, such as a managed bean.<\/p>\n<p>Several built-in constraints are available in the <code>javax.validation.constraints<\/code> package. <a title=\"Built-In Bean Validation Constraints\" onclick=\"javascript:_gaq.push(['_trackEvent','outbound-article','http:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/gircz.html#gkagk']);\" href=\"http:\/\/docs.oracle.com\/javaee\/6\/tutorial\/doc\/gircz.html#gkagk\" target=\"_blank\">The Java EE 6 Tutorial<\/a> lists all the built-in constraints.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\nConstraints in Bean Validation are expressed via Java annotations:<\/p>\n<pre class=\" brush:java\">public class Person {\r\n    @NotNull\r\n    @Size(min = 2, max = 50)\r\n    private String name;\r\n    \/\/ ...\r\n}<\/pre>\n<h2>Bean Validation and RESTful web services<\/h2>\n<p>JAX-RS 1.0 provides great support for extracting request values and binding them into Java fields, properties and parameters using annotations such as <code>@HeaderParam<\/code>, <code>@QueryParam<\/code>, etc. It also supports binding of request entity bodies into Java objects via non-annotated parameters (i.e., parameters that are not annotated with any of the JAX-RS annotations). Currently, any additional validation on these values in a resource class must be performed programmatically.<\/p>\n<p>The next release, JAX-RS 2.0, includes a proposal to enable validation annotations to be combined with JAX-RS annotations. For example, given the validation annotation <code>@Pattern<\/code>, the following example shows how form parameters could be validated.<\/p>\n<pre class=\" brush:java\">@GET\r\n@Path('{id}')\r\npublic Person getPerson(\r\n        @PathParam('id')\r\n        @Pattern(regexp = '[0-9]+', message = 'The id must be a valid number')\r\n        String id) {\r\n    return persons.get(id);\r\n}<\/pre>\n<p>However, at the moment, the only solution is to use a proprietary implementation. What is presented next is a solution based on the <a title=\"RESTEasy\" onclick=\"javascript:_gaq.push(['_trackEvent','outbound-article','http:\/\/www.jboss.org\/resteasy']);\" href=\"http:\/\/www.jboss.org\/resteasy\" target=\"_blank\">RESTEasy<\/a> framework from JBoss that complies with the JAX-RS specification and adds a RESTful validation interface through the annotation <code>@ValidateRequest<\/code>.<\/p>\n<p>The exported interface allows us to create our own implementation. However, there is already one widely used and to which RESTEasy also provides a seamless integration. This implementation is <a title=\"Hibernate Validator &amp; Bean Validation TCK\" onclick=\"javascript:_gaq.push(['_trackEvent','outbound-article','http:\/\/www.hibernate.org\/subprojects\/validator.html']);\" href=\"http:\/\/www.hibernate.org\/subprojects\/validator.html\" target=\"_blank\">Hibernate Validator<\/a>. This provider can be added to the project through the following Maven dependencies:<\/p>\n<pre class=\" brush:xml\">&lt;dependency&gt;\r\n    &lt;groupId&gt;org.jboss.resteasy&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;resteasy-jaxrs&lt;\/artifactId&gt;\r\n    &lt;version&gt;2.3.2.Final&lt;\/version&gt;\r\n    &lt;scope&gt;provided&lt;\/scope&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n    &lt;groupId&gt;org.jboss.resteasy&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;resteasy-hibernatevalidator-provider&lt;\/artifactId&gt;\r\n    &lt;version&gt;2.3.2.Final&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p><strong>Note:<\/strong> without declaring the <code>@ValidateRequest<\/code> at class or method level, no validation will occur despite having applied constraint annotations on the methods, e.g. the example above.<\/p>\n<pre class=\" brush:java\">@GET\r\n@Path('{id}')\r\n@ValidateRequest\r\npublic Person getPerson(\r\n        @PathParam('id')\r\n        @Pattern(regexp = '[0-9]+', message = 'The id must be a valid number')\r\n        String id) {\r\n    return persons.get(id);\r\n}<\/pre>\n<p>After applying the annotation, the parameter <code>id<\/code> will be automatically validated when a request is made.<br \/>\nYou can of course validate entire entities instead of single fields by using the annotation <code>@Valid<\/code>. We could for example have one method that accepts a <code>Person<\/code> object and validates it.<\/p>\n<pre class=\" brush:java\">@POST\r\n@Path('\/validate')\r\n@ValidateRequest\r\npublic Response validate(@Valid Person person) {\r\n    \/\/ ...\r\n}<\/pre>\n<h4>Note:<\/h4>\n<p> By default, when validation fails an exception is thrown by the container and a HTTP 500 status is returned to the client. This default behavior can\/should be overridden, allowing us to customize the Response that is returned to the client through exception mappers.<\/p>\n<h2>Internationalization<\/h2>\n<p>Until now we have been using the default or hard-coded error messages, but this is both a bad practice and not flexible at all. I18n is part of the Bean Validation specification and allows us to specify custom error messages using a resource property file. The default resource file name is <code>ValidationMessages.properties<\/code> and must include pairs of properties\/values like:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\" brush:bash\">person.id.pattern=The person id must be a valid number\r\nperson.name.size=The person name must be between {min} and {max} chars long<\/pre>\n<h4>Note:<\/h4>\n<p> <code>{min}<\/code>, <code>{max}<\/code> refer to properties of the constraint to which the message will be associated with.<\/p>\n<p>Those defined messages can then be injected on the validation constraints as:<\/p>\n<pre class=\" brush:java\">@POST\r\n@Path('create')\r\n@Consumes(MediaType.APPLICATION_FORM_URLENCODED)\r\npublic Response createPerson(\r\n        @FormParam('id')\r\n        @Pattern(regexp = '[0-9]+', message = '{person.id.pattern}')\r\n        String id,\r\n        @FormParam('name')\r\n        @Size(min = 2, max = 50, message = '{person.name.size}')\r\n        String name) {\r\n    Person person = new Person();\r\n    person.setId(Integer.valueOf(id));\r\n    person.setName(name);\r\n    persons.put(Integer.valueOf(id), person);\r\n    return Response.status(Response.Status.CREATED).entity(person).build();\r\n}<\/pre>\n<p>To provide translations to other languages, one must create a new <code>ValidationMessages_XX.properties<\/code> file with the translated messages, where <code>XX<\/code> is the code of the language being provided.<\/p>\n<p>Unfortunately Hibernate Validator provider doesn\u2019t support i18n based on a specific HTTP request. It does not take <code>Accept-Language<\/code> HTTP header into account and always uses the default <code>Locale<\/code> as provided by <code>Locale.getDefault()<\/code>. To be able to change the <code>Locale<\/code> using the <code>Accept-Language<\/code> HTTP header (e.g., changing the language in the browser options), a custom implementation must be provided.<\/p>\n<h2>Custom validator provider<\/h2>\n<p>The code below intends to address this issue and has been tested with <a title=\"JBoss Application Server\" onclick=\"javascript:_gaq.push(['_trackEvent','outbound-article','http:\/\/www.jboss.org\/jbossas\/']);\" href=\"http:\/\/www.jboss.org\/jbossas\/\" target=\"_blank\">JBoss AS 7.1<\/a>.<\/p>\n<p>The first thing to do is to remove the Maven <code>resteasy-hibernatevalidator-provider<\/code> dependency, since we are providing our own provider, and add Hibernate Validator dependency:<\/p>\n<pre class=\" brush:xml\">&lt;dependency&gt;\r\n    &lt;groupId&gt;org.hibernate&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;hibernate-validator&lt;\/artifactId&gt;\r\n    &lt;version&gt;4.2.0.Final&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>Next create a custom message interpolator to adjust the default <code>Locale<\/code> used.<\/p>\n<pre class=\" brush:java\">public class LocaleAwareMessageInterpolator extends\r\n        ResourceBundleMessageInterpolator {\r\n\r\n    private Locale defaultLocale = Locale.getDefault();\r\n\r\n    public void setDefaultLocale(Locale defaultLocale) {\r\n        this.defaultLocale = defaultLocale;\r\n    }\r\n\r\n    @Override\r\n    public String interpolate(final String messageTemplate,\r\n            final Context context) {\r\n        return interpolate(messageTemplate, context, defaultLocale);\r\n    }\r\n\r\n    @Override\r\n    public String interpolate(final String messageTemplate,\r\n            final Context context, final Locale locale) {\r\n        return super.interpolate(messageTemplate, context, locale);\r\n    }\r\n}<\/pre>\n<p>The next step is to provide a <code>ValidatorAdapter<\/code>. This interface was introduced to decouple RESTEasy from the real validation API.<\/p>\n<pre class=\" brush:java\">public class RESTValidatorAdapter implements ValidatorAdapter {\r\n\r\n    private final Validator validator;\r\n\r\n    private final MethodValidator methodValidator;\r\n\r\n    private final LocaleAwareMessageInterpolator interpolator = new LocaleAwareMessageInterpolator();\r\n\r\n    public RESTValidatorAdapter() {\r\n        Configuration&lt;?&gt; configuration = Validation.byDefaultProvider()\r\n                .configure();\r\n        this.validator = configuration.messageInterpolator(interpolator)\r\n                .buildValidatorFactory().getValidator();\r\n        this.methodValidator = validator.unwrap(MethodValidator.class);\r\n    }\r\n\r\n    @Override\r\n    public void applyValidation(Object resource, Method invokedMethod,\r\n            Object[] args) {\r\n        \/\/ For the i8n to work, the first parameter of the method being validated must be a HttpHeaders\r\n        if ((args != null) &amp;&amp; (args[0] instanceof HttpHeaders)) {\r\n            HttpHeaders headers = (HttpHeaders) args[0];\r\n            List&lt;Locale&gt; acceptedLanguages = headers.getAcceptableLanguages();\r\n            if ((acceptedLanguages != null) &amp;&amp; (!acceptedLanguages.isEmpty())) {\r\n                interpolator.setDefaultLocale(acceptedLanguages.get(0));\r\n            }\r\n        }\r\n\r\n        ValidateRequest resourceValidateRequest = FindAnnotation\r\n                .findAnnotation(invokedMethod.getDeclaringClass()\r\n                        .getAnnotations(), ValidateRequest.class);\r\n\r\n        if (resourceValidateRequest != null) {\r\n            Set&lt;ConstraintViolation&lt;?&gt;&gt; constraintViolations = new HashSet&lt;ConstraintViolation&lt;?&gt;&gt;(\r\n                    validator.validate(resource,\r\n                            resourceValidateRequest.groups()));\r\n\r\n            if (constraintViolations.size() &gt; 0) {\r\n                throw new ConstraintViolationException(constraintViolations);\r\n            }\r\n        }\r\n\r\n        ValidateRequest methodValidateRequest = FindAnnotation.findAnnotation(\r\n                invokedMethod.getAnnotations(), ValidateRequest.class);\r\n        DoNotValidateRequest doNotValidateRequest = FindAnnotation\r\n                .findAnnotation(invokedMethod.getAnnotations(),\r\n                        DoNotValidateRequest.class);\r\n\r\n        if ((resourceValidateRequest != null || methodValidateRequest != null)\r\n                &amp;&amp; doNotValidateRequest == null) {\r\n            Set&lt;Class&lt;?&gt;&gt; set = new HashSet&lt;Class&lt;?&gt;&gt;();\r\n            if (resourceValidateRequest != null) {\r\n                for (Class&lt;?&gt; group : resourceValidateRequest.groups()) {\r\n                    set.add(group);\r\n                }\r\n            }\r\n\r\n            if (methodValidateRequest != null) {\r\n                for (Class&lt;?&gt; group : methodValidateRequest.groups()) {\r\n                    set.add(group);\r\n                }\r\n            }\r\n\r\n            Set&lt;MethodConstraintViolation&lt;?&gt;&gt; constraintViolations = new HashSet&lt;MethodConstraintViolation&lt;?&gt;&gt;(\r\n                    methodValidator.validateAllParameters(resource,\r\n                            invokedMethod, args,\r\n                            set.toArray(new Class&lt;?&gt;[set.size()])));\r\n\r\n            if (constraintViolations.size() &gt; 0) {\r\n                throw new MethodConstraintViolationException(\r\n                        constraintViolations);\r\n            }\r\n        }\r\n    }\r\n}<\/pre>\n<h2>Warn:<\/h2>\n<p> <code>@HttpHeaders<\/code> needs to be injected as the first parameter of the methods that are going to be validated:<\/p>\n<pre class=\" brush:java\">@POST\r\n@Path('create')\r\n@Consumes(MediaType.APPLICATION_FORM_URLENCODED)\r\npublic Response createPerson(\r\n        @Context HttpHeaders headers,\r\n        @FormParam('id')\r\n        @Pattern(regexp = '[0-9]+', message = '{person.id.pattern}')\r\n        String id,\r\n        @FormParam('name')\r\n        @Size(min = 2, max = 50, message = '{person.name.size}')\r\n        String name) {\r\n    Person person = new Person();\r\n    person.setId(Integer.valueOf(id));\r\n    person.setName(name);\r\n    persons.put(id, person);\r\n    return Response.status(Response.Status.CREATED).entity(person).build();\r\n}<\/pre>\n<p>Finally, create the provider that will select the classes above to be used to validate Bean Validation constraints:<\/p>\n<pre class=\" brush:java\">@Provider\r\npublic class RESTValidatorContextResolver implements\r\n        ContextResolver&lt;ValidatorAdapter&gt; {\r\n\r\n    private static final RESTValidatorAdapter adapter = new RESTValidatorAdapter();\r\n\r\n    @Override\r\n    public ValidatorAdapter getContext(Class&lt;?&gt; type) {\r\n        return adapter;\r\n    }\r\n}<\/pre>\n<h2>Mapping Exceptions<\/h2>\n<p>The Bean Validation API reports error conditions using exceptions of type <code>javax.validation.ValidationException<\/code> or any of its subclasses. Applications can supply custom exception mapping providers for any exception. A JAX-RS implementation MUST always use the provider whose generic type is the nearest superclass of the exception, with application-defined providers taking precedence over built-in providers.<\/p>\n<p>The exception mapper may look like:<\/p>\n<pre class=\" brush:java\">@Provider\r\npublic class ValidationExceptionMapper implements\r\n        ExceptionMapper&lt;MethodConstraintViolationException&gt; {\r\n\r\n    @Override\r\n    public Response toResponse(MethodConstraintViolationException ex) {\r\n        Map&lt;String, String&gt; errors = new HashMap&lt;String, String&gt;();\r\n        for (MethodConstraintViolation&lt;?&gt; methodConstraintViolation : ex\r\n                .getConstraintViolations()) {\r\n            errors.put(methodConstraintViolation.getParameterName(),\r\n                    methodConstraintViolation.getMessage());\r\n        }\r\n        return Response.status(Status.PRECONDITION_FAILED).entity(errors)\r\n                .build();\r\n    }\r\n}<\/pre>\n<p>The above example shows the implementation of an <code>ExceptionMapper<\/code> that maps exceptions of type <code>MethodConstraintViolationException<\/code>. This exception is thrown by Hibernate Validator implementation when the validation of one or more parameters of a method annotated with the <code>@ValidateRequest<\/code> fails. This ensures that the client receives a formatted response instead of just the exception being propagated from the resource.<\/p>\n<h2>Source code<\/h2>\n<p>The source code used for this post is available on <a title=\"JAX-RS Bean Validation I18N\" onclick=\"javascript:_gaq.push(['_trackEvent','outbound-article','http:\/\/github.com\/samaxes\/jaxrs-beanvalidation']);\" href=\"https:\/\/github.com\/samaxes\/jaxrs-beanvalidation\" target=\"_blank\">GitHub<\/a>.<\/p>\n<h4>Warn:<\/h4>\n<p> rename the resource property file to have the file <code>ValidationMessages.properties<\/code> (i.e., without any suffix) to map to the <code>Locale<\/code> as returned by <code>Locale.getDefault()<\/code>.<\/p>\n<p><strong>Related Posts<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.samaxes.com\/2006\/12\/java-and-utf-8-encoding\/\">Java and UTF-8 encoding<\/a><\/li>\n<li><a href=\"http:\/\/www.samaxes.com\/2012\/11\/running-drools-5-4-0-final-as-a-jboss-as-7-module\/\">Running Drools 5.4.0 Final as a JBoss AS 7 module<\/a><\/li>\n<li><a href=\"http:\/\/www.samaxes.com\/2012\/10\/comparing-device-description-repositories\/\">Comparing Device Description Repositories<\/a><\/li>\n<li><a href=\"http:\/\/www.samaxes.com\/2012\/05\/javaee-testing-introduction-arquillian-shrinkwrap\/\">Java EE 6 Testing Part II \u2013 Introduction to Arquillian and ShrinkWrap<\/a><\/li>\n<li><a href=\"http:\/\/www.samaxes.com\/2011\/12\/javaee-testing-ejb31-embeddable\/\">Java EE 6 Testing Part I \u2013 EJB 3.1 Embeddable API<\/a><\/li>\n<li><a href=\"http:\/\/www.samaxes.com\/2012\/11\/running-drools-5-4-0-final-as-a-jboss-as-7-module\/\" rel=\"prev\">Previous Entry: Running Drools 5.4.0 Final as a JBoss AS 7 module<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong><em>Reference: <\/em><\/strong><a href=\"http:\/\/www.samaxes.com\/2013\/01\/beanvalidation-with-jaxrs-in-javaee6\/\">Integrating Bean Validation with JAX-RS in Java EE 6<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Samuel Santos at the <a href=\"http:\/\/www.samaxes.com\/\">Samaxes<\/a> blog.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by constraints in the form of annotations placed on a field, method, or class of a JavaBeans component, such as a managed bean. Several built-in constraints are available in the javax.validation.constraints package. &hellip;<\/p>\n","protected":false},"author":228,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[289,439,54],"class_list":["post-6950","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-java-ee6","tag-jax-rs","tag-restful-web-services"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Integrating Bean Validation with JAX-RS in Java EE 6<\/title>\n<meta name=\"description\" content=\"JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Integrating Bean Validation with JAX-RS in Java EE 6\" \/>\n<meta property=\"og:description\" content=\"JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-01-14T17:00:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-06-11T07:14:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Samuel Santos\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/samaxes\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Samuel Santos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html\"},\"author\":{\"name\":\"Samuel Santos\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cd56a59549f8c033272e083db1e9c216\"},\"headline\":\"Integrating Bean Validation with JAX-RS in Java EE 6\",\"datePublished\":\"2013-01-14T17:00:12+00:00\",\"dateModified\":\"2013-06-11T07:14:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html\"},\"wordCount\":879,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"Java EE6\",\"JAX-RS\",\"RESTful Web Services\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html\",\"name\":\"Integrating Bean Validation with JAX-RS in Java EE 6\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2013-01-14T17:00:12+00:00\",\"dateModified\":\"2013-06-11T07:14:22+00:00\",\"description\":\"JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/01\\\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Integrating Bean Validation with JAX-RS in Java EE 6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cd56a59549f8c033272e083db1e9c216\",\"name\":\"Samuel Santos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b6c5678bb5209583d05b239c02310b8d782188cbae9cff83b0e78e3f1f0e69fc?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b6c5678bb5209583d05b239c02310b8d782188cbae9cff83b0e78e3f1f0e69fc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b6c5678bb5209583d05b239c02310b8d782188cbae9cff83b0e78e3f1f0e69fc?s=96&d=mm&r=g\",\"caption\":\"Samuel Santos\"},\"description\":\"Java and Open Source evangelist, JUG leader and Web advocate for web standards and semantic technologies.\",\"sameAs\":[\"http:\\\/\\\/www.samaxes.com\\\/\",\"http:\\\/\\\/www.linkedin.com\\\/in\\\/samaxes\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/samaxes\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Samuel-Santos\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Integrating Bean Validation with JAX-RS in Java EE 6","description":"JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html","og_locale":"en_US","og_type":"article","og_title":"Integrating Bean Validation with JAX-RS in Java EE 6","og_description":"JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by","og_url":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-01-14T17:00:12+00:00","article_modified_time":"2013-06-11T07:14:22+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Samuel Santos","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/samaxes","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Samuel Santos","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html"},"author":{"name":"Samuel Santos","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cd56a59549f8c033272e083db1e9c216"},"headline":"Integrating Bean Validation with JAX-RS in Java EE 6","datePublished":"2013-01-14T17:00:12+00:00","dateModified":"2013-06-11T07:14:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html"},"wordCount":879,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["Java EE6","JAX-RS","RESTful Web Services"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html","url":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html","name":"Integrating Bean Validation with JAX-RS in Java EE 6","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2013-01-14T17:00:12+00:00","dateModified":"2013-06-11T07:14:22+00:00","description":"JavaBeans Validation (Bean Validation) is a new validation model available as part of Java EE 6 platform. The Bean Validation model is supported by","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/01\/integrating-bean-validation-with-jax-rs-in-java-ee-6.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Integrating Bean Validation with JAX-RS in Java EE 6"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cd56a59549f8c033272e083db1e9c216","name":"Samuel Santos","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b6c5678bb5209583d05b239c02310b8d782188cbae9cff83b0e78e3f1f0e69fc?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b6c5678bb5209583d05b239c02310b8d782188cbae9cff83b0e78e3f1f0e69fc?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b6c5678bb5209583d05b239c02310b8d782188cbae9cff83b0e78e3f1f0e69fc?s=96&d=mm&r=g","caption":"Samuel Santos"},"description":"Java and Open Source evangelist, JUG leader and Web advocate for web standards and semantic technologies.","sameAs":["http:\/\/www.samaxes.com\/","http:\/\/www.linkedin.com\/in\/samaxes","https:\/\/x.com\/https:\/\/twitter.com\/samaxes"],"url":"https:\/\/www.javacodegeeks.com\/author\/Samuel-Santos"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/6950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/228"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=6950"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/6950\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=6950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=6950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=6950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}