Here is the validation.xml
<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd"
xmlns="http://jboss.org/xml/ns/javax/validation/mapping" version="1.1">
<default-package>com.esq.rbac.model</default-package>
<bean class="Tenant" ignore-annotations="true">
...
<field name="ivrPin">
<constraint annotation="javax.validation.constraints.Size">
<element name="min">6</element>
<element name="max">6</element>
<message>IVR Pin must be 6 digit numeric</message>
</constraint>
<constraint annotation="javax.validation.constraints.Pattern">
<element name="regexp">[0-9]+</element>
</constraint>
</field>
</bean>
During execution getting error saying
c.e.u.imports.Main [run] - HV000115: Error parsing mapping file.
javax.validation.ValidationException: HV000115: Error parsing mapping file.
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a:
Invalid content was found starting with element 'message'. One of '{"http://jboss.org/xml/ns/javax/validation/mapping":element}' is expected.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
How to include the error message properly
You just need to make one change by placing your
messagedirectly afterconstraint annotationtag, before theelementtags.The reason for this is as follows:
If you look at the xsd file for validation-mapping:
validation-mapping-1.1.xsd
It is using
xs:sequencetag which specifies that the child elements must appear in a sequence. Refer element sequence. Here message attribute comes before other attributes like groups, payload or element.