Annotation based request validation <p>I'm trying to validate a numeric variable in the request, what I'm trying to achieve, for this field to be non null and numeric. I want to have different errors reported for null and conversion error.</p> <p>I was trying to use org.springframework.format.annotation.NumberFormat</p> <p>Why doesn't the @NumberFormat doesn't have default message property? Is there a reason why this has been missed. I'll now have to customize it as I'm not using the message resource bundles.</p> <pre><code>public class AddToJobsShortListWSRequest implements Serializable { @NumberFormat(style = NumberFormat.Style.NUMBER) @NotNull(message="ASL01") private Long userDetailId; </code></pre> <p>controller</p> <pre><code>public ResponseEntity&lt;String&gt; handlePostRequest(String xmlRequest, String... externalIds) { ResponseEntity&lt;String&gt; response = null; Set&lt;Enum&gt; enums = new HashSet&lt;Enum&gt;(); AddToJobsShortListWSRequest addToJobsShortListWSRequest = serializationDeserializationSupport.fromString(xmlRequest, AddToJobsShortListWSRequest.class); if(!jsonRequestValidator.validate(AddToJobsShortListWSError.class, enums, addToJobsShortListWSRequest)) { response = getBadRequestErrorResponseEntity(enums); } else{ ..... } </code></pre> <p>Validator</p> <pre><code> private void validate(@SuppressWarnings("rawtypes") Class enumClass, Object object, @SuppressWarnings("rawtypes") Set&lt;Enum&gt; enums) { BindException errors = new BindException(object, "object"); validator.validate(object, errors); @SuppressWarnings({"rawtypes"}) List fieldErrors = errors.getFieldErrors(); for (int i = 0; i &lt; fieldErrors.size(); i++) { if (fieldErrors.get(i) instanceof FieldError) { String m = ((FieldError) fieldErrors.get(i)).getDefaultMessage(); enums.add(Enum.valueOf(enumClass, m)); } } } </code></pre> <p>Is there any other annotation based validation applicable here? Also, what is the order of validation, which one kicks in first, NumberFormat, NotNull?</p> <p>Thanks in advance :)</p>