[bv-dev] Value extraction open issue #2: per constraint ConstraintsApplyTo?

Gunnar Morling gunnar at hibernate.org
Wed Jan 18 09:19:15 EST 2017


So I got confirmation from the JDK team that there is no guaranteed
order for retrieved annotations in the general case, causing any
index-based approach to fail.

The problem I see about the meta-annotation approach is that it
doesn't allow to re-use existing constraints without additional
changes, i.e. there's a migration hurdle for 3rd-party constraints
(similar to having a dedicated validationWrappedValue() member).

Now Emmanuel made the proposal to use the payload() feature for this:

    @Size(1) Size(min=3, payload=Unwrapping.Unwrap.class) StringList nicknames;

While it feels a bit hack-ish, it puts the setting to the right level
(individual constraints as opposed to entire elements). So I think
it's a good basis, so we could move on with this for the time being
and hopefully get some exposure + feedback in an Alpha release.

--Gunnar



2017-01-17 17:22 GMT+01:00 Matt Benson <mbenson at apache.org>:
>
>
> On Tue, Jan 17, 2017 at 6:56 AM, Emmanuel Bernard <emmanuel at hibernate.org>
> wrote:
>>
>>
>> On 13 Jan 2017, at 18:54, Matt Benson <mbenson at apache.org> wrote:
>>
>> As I warned, however, defining these might become tedious. It might be
>> helpful to define a mechanism (like that supported by Spring) to map
>> annotation elements:
>>
>> @Size
>> @ConstraintsApplyTo(WRAPPED_VALUE)
>> @Constraint
>> public @interface WrappedSize {
>>
>>   @MapTo(type=Size.class, attribute="min")
>>   int min() default 0;
>>
>>   @MapTo(type=Size.class, attribute="max")
>>   int max() default Integer.MAX_VALUE;
>>
>>   String message() default "";
>>   Class<?> groups() default {};
>>   Class<? extends Payload>[] payload() default {};
>> }
>>
>> @Size(1) @WrappedSize(min=3) StringList nicknames;
>>
>>
>> If you mean something like @MapTo, the spec already has that via
>> @OverridesAttribute
>> AFAIK we invented it.
>>
>
> Sorry, it's been awhile since I've used BV in real life. But yes, that's
> what I mean.
>
> Matt
>>
>> _______________________________________________
>> beanvalidation-dev mailing list
>> beanvalidation-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev
>
>
>
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev


More information about the beanvalidation-dev mailing list