-->
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: String[] element of Annotation in the validation message
PostPosted: Thu Jul 14, 2011 4:50 pm 
Newbie

Joined: Wed Jul 13, 2011 9:40 pm
Posts: 4
So I have a constraint validation defined as follows:

Code:
@Target(value={ElementType.METHOD,ElementType.FIELD,ElementType.ANNOTATION_TYPE,ElementType.CONSTRUCTOR,ElementType.PARAMETER})
@Retention(value=RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = AllowedValuesValidator.class)
public @interface AllowedValues {
   String[] values();
   
   String message() default "{com.test.AllowedValues.message}";

    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default {};
}


And I want to tell the user the list of allowed values when validation fails. I tried adding:

Code:
com.test.AllowedValues.message=must be one of {values}


to the ValidationMessage.properties and what I get is:

Quote:
must be one of [Ljava.lang.String;@536b98c3


is there a sytax I can use in the ValidationMessage.properties to tell hibernate to list all of the elements?

thanks,

matt


Top
 Profile  
 
 Post subject: Re: String[] element of Annotation in the validation message
PostPosted: Fri Jul 15, 2011 4:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi Matt,

Good catch, actually there is not special syntax. At the moment we just call toString on the parameter and hence the behavior. The spec jsut says:
Quote:
Message parameters are extracted from the message string. Those matching the name of an attribute of the constraint declaration are replaced by the value of that attribute.

There are no clear guidelines on how an array value should be interpolated. I would assume something like [<value1>,<value2>,...] would make sense. I created an issue for that - https://hibernate.onjira.com/browse/HV-506

--Hardy


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.