-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Custom constraints vs custom validator implementations
PostPosted: Tue Mar 03, 2015 4:49 am 
Newbie

Joined: Thu Dec 23, 2004 7:23 am
Posts: 12
Location: Melbourne
Hi,

Are there scenarios in which it is recommended to implement a custom javax.validation.Validator rather than implementing custom constraints and annotating classes with them?

To be more precise, let's pretend we have a model (entity, DTO, etc.) that has a complex validation logic. Are there scenarios in which it is advised that rather than annotating our DTO with a custom constraint annotation such as given in the following listing:

Code:
@ComplexConstraint
public class MyComplexDto {
}


one should instead implement a custom Validator:

Code:
Validator validator = new MyCustomValidator(); // this can be obtained via injection, etc.
validator.validate(myComplexDto);


I always assumed that Validator is primarily meant to be implemented by implementations of the JSR 303 spec, rather than end users on a case by case basis.

What do you think?

Thanks in advance,
Behrang


Top
 Profile  
 
 Post subject: Re: Custom constraints vs custom validator implementations
PostPosted: Tue Mar 03, 2015 9:21 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Nan, you can manually validate things if you want but I would not implement java.validation.Validator as a user.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.