-->
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.  [ 3 posts ] 
Author Message
 Post subject: Is there a way to set up 'standoff' validations?
PostPosted: Wed Dec 23, 2015 3:35 pm 
Newbie

Joined: Wed Dec 23, 2015 3:33 pm
Posts: 2
Is there a way to separate a class from its validation annotations? If I have a public API and I'd rather not introduce a dependency on the annotation classes, can I keep the data somewhere else?


Top
 Profile  
 
 Post subject: Re: Is there a way to set up 'standoff' validations?
PostPosted: Thu Dec 24, 2015 5:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
You can separate the validation rules to XML:

https://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/chapter-xml-configuration.html


Top
 Profile  
 
 Post subject: Re: Is there a way to set up 'standoff' validations?
PostPosted: Mon Jan 04, 2016 7:35 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

You can use XML as outlined by Vlad (or, the API for programmatic constraint declaration in Hibernate Validator).

I'd be interested in your rationale for avoiding that dependency, though. If you constrain your public API types, the constraints are part of the API, the user needs to adhere to these constraints (or they provide some form of guarantee to him, if e.g. constraining method return values). So IMHO it makes sense to expose the constraint information to API users as well (that's also the reason why all the Bean Validation constraint annotation types are meta-annotated with @Documented, which will cause them to be listed in JavaDocs of annotated elements). So it'd be interesting to learn more about your use case.

Btw. annotated classes can be loaded also if the annotation types are not present at runtime, so your API should still be usable also without the constraint annotation types (of course validation will not work then).

Cheers,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.