-->
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: @Valid not applying to elements of unwrapped Iterable
PostPosted: Wed May 28, 2014 9:14 pm 
Newbie

Joined: Wed May 28, 2014 8:56 pm
Posts: 1
I have a field in a bean annotated as such:

Code:
@UnwrapValidatedValue
@Valid
private Optional<List<MyCustomType>> stuff = Optional.absent();


I would hope that the @Valid would cause each of the instances of MyCustomType in the List to be validated, but as of yet I have not been able to get that to work. The unwrapping works correctly so that the List itself is validated if I apply @NotNull or other such annotations, but the @Valid annotation does not cause the elements of the list to be validated.

My value unwrapper looks like:

Code:
import org.hibernate.validator.spi.valuehandling.ValidatedValueUnwrapper;

import com.fasterxml.classmate.TypeResolver;
import com.google.common.base.Optional;

public class OptionalValueUnwrapper extends ValidatedValueUnwrapper<Optional<?>>
{
   private final TypeResolver typeResolver = new TypeResolver();

   @Override
   public Object handleValidatedValue(Optional<?> value)
   {
      if (!value.isPresent()) {
          return null;
      }
      return value.get();
   }

   @Override
   public Type getValidatedValueType(Type valueType)
   {
           ResolvedType resolvedType = typeResolver.resolve(valueType);
           return resolvedType.typeParametersFor(Optional.class).get(0).getErasedType();
   }
}


I am using hibernate-validator 5.1.1.Final

Any suggestions?

Thank you!


Top
 Profile  
 
 Post subject: Re: @Valid not applying to elements of unwrapped Iterable
PostPosted: Thu May 29, 2014 6:25 am 
Hibernate Team
Hibernate Team

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

I think you've hit a bug. I've filed https://hibernate.atlassian.net/browse/HV-895 for this.

Maybe you'd like to help out with this and take a look at the possible cause yourself? I'd assume the handling of unwrapping and cascading validation in ValidatorImpl doesn't take the combination of the two into account properly.

--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.  [ 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.