Very corner case, and googling around does not seem to help.
I have to use xml validation (generated code) and the scenario is similar to:
// This file was generated by the JavaTM Architecture for XML
Binding(JAXB) Reference Implementation, v2.2.4
...
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "xxx", propOrder
= { ... }) @XmlRootElement(name = "xxx") public class Class01DTO
implements Serializable { ...
@XmlElement(required = true)
protected BetslipDTO.SlipPlacement slipPlacement;
...
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { ...
})
public static class Class02
implements Serializable
{
private final static long serialVersionUID = ...;
protected String stringToValidate;
}
}
I am not confident on how to validate “stringToValidate”. I have a constraints-mapping.xml with something like:
<bean class="com.etc.Class01DTO.Class02">
<field name="stringToValidate">
<constraint annotation="javax.validation.constraints.NotNull">
</constraint>
</field>
</bean>
That just generates an error. Different combinations have been tried, without a result. Has anyone faced the same case?
I assume it is clear that the code is generated, so cannot use the option of having annotation based validation…
Error is similar to the following when doing a build
…
shouldValidateSpringContext(com.etc.TestBetSpringContext): Error creating bean with name 'validatorFactoryBean' defined in class path resource [spring/bet-service.xml]: Invocation of init method failed; nested exception is javax.validation.ValidationException: HV000065: Unable to load class: com.etc.Class01DTO.Class02.
If you want to specify a nested classname, you should rather use
com.etc.Class01DTO$Class02, after compilation of those classes, take a look at target directory, you’ll find that all nested classes are compiled into separate files with$in their names.