-->
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: @NotNull and @UnwrapValidatedValue
PostPosted: Fri Aug 07, 2015 1:05 pm 
Newbie

Joined: Fri Aug 07, 2015 12:58 pm
Posts: 1
Hi,

Given this POJO

The following class allows both Optional.empty() and null values.
class X {
@UnwrapValidatedValue
@Min(2)
Optional<Integer> foo;
}

The following class neither allows Optional.empty() and null values.
class X {
@NotNull
@UnwrapValidatedValue
@Min(2)
Optional<Integer> foo;
}

I would like to be able to allow Optional.empty() but not allow null values. The idea is that foo could have no value, but the proper way to convey that is to use Optional.empty() but not null.

Is there a way to do that ? I also could not find the unit tests that check these kind of scenarios.

Regards,
Itai


Top
 Profile  
 
 Post subject: Re: @NotNull and @UnwrapValidatedValue
PostPosted: Fri Apr 28, 2017 4:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Jan 05, 2017 6:04 am
Posts: 13
With Hibernate Validator 6.0.0.Alpha2, you can do the following:

@NotNull(payload = Unwrapping.Skip)
private Optional<Integer> foo;


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.