I was looking over
this post of using JSR-303 to validate a collection of objects. The solution works great with annotations, but I can't seem to get it to work with the Hibernate Validator XML formatted configuration.
For example, I have code similar to this:
Code:
public class DataSet
{
Collection<Data> dataCollection;
public Collection<Data> getDataCollection() {...}
}
From there, I have a custom validator/annotation DataValidator/@ValidData.
In XML, I do this first:
Code:
<bean class="DataSet"
ignore-annotations="true">
<field name="dataCollection">
<valid/>
<constraint annotation="ValidData"/>
</field>
</bean>
However, I get the following exception:
Code:
Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be found for type: java.util.Collection<DataSet>
So I swap the <valid> tag with the <constraint> one in the XML. It seems this is not valid with the XSD schema and the XML can no longer be parsed.
Code:
<bean class="DataSet"
ignore-annotations="true">
<field name="dataCollection">
<constraint annotation="ValidData"/>
<valid/> <!-- moved this down a line -->
</field>
</bean>
Code:
Exception in thread "main" javax.validation.ValidationException: Error parsing mapping file.
Does anyone know how I can use XML to validate this collection with must custom validator?
P.S. If anyone is sure about their solution, feel free to get some points on Stack Overflow -- have it
cross posted here.