-->
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: Constraints on 'union types'?
PostPosted: Thu Apr 03, 2008 3:36 pm 
Newbie

Joined: Sun Mar 30, 2008 12:19 am
Posts: 15
Say I have a type which can be an integer or an enumeration, would it be possible to do:

@NotNull @Min(0) @OneOf({Integer, MyEnum}) Object foo;

(@OneOf is an example, and gives a list of acceptable assignable types )

It looks like constraints are advised to accept null as a value to allow NotNull to work, but to fail if data is not of a type that the constraint can handle.

Are constraints meant to ignore data that is of a type that isn't accepted, or are these cases expected to be handled by custom annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 7:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@OneOf really is meant to accept all types and return true only on a subset of types.

I think generally speaking the spec recommendation is good. If the validation logic does not expect a given type, it should raise an exception. For example, let's say you apply @CreditCard on an URL object, an exception is thrown.

_________________
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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.