users@jersey.java.net

[Jersey] Jersey bean validation and generics

From: Matthew Cordes <cordes.matthew_at_gmail.com>
Date: Thu, 10 Oct 2013 01:43:31 -0400

Hello,

I'm running some issues with bean validation and generics. When my bean
includes a list of a generic type bean validation isn't being performed on
the items in the list. If I remove the generic type from the bean it works
as expected (and validates both the bean and the nested beans).

Some examples:

This doesn't work. It's just validating the properties on *Bean* and
skipping *nestedBeans*. I'm not seeing an error message it's simply
skipping the validation.

public class Bean<T> {
    @Valid
    private List<T> nestedBeans;
}


This *does* work, and validates both *Bean *and all the *NestedBean*objects.

public class Bean {
    @Valid
    private List<NestedBean> nestedBeans;
}

I'm using Jersey 2.3.1 with hibernate-validator 5.0.1.Final.

Why doesn't the first version work? And what is the recommended solution?

Any thoughts?
-Matt