title: How to customize default message for BigDecimal
body: <p>Here are the models:</p>
  
  <pre><code>public class myFormData {
      private BigDecimal trackingNumber;
  
      @Valid
      private List&lt;myCustomRecord&gt; records = new ArrayList&lt;myCustomRecord&gt;();
  }
  
  public class myCustomRecord {
      //the field also appears here (for child records)
      private BigDecimal trackingNumber;
  }
  </code></pre>
  
  <p>I have a controller method which receives this object at some point to do a save.</p>
  
  <pre><code>public @ResponseBody ValidationResponse save(Model model,
          @Valid myFormData formData, BindingResult result,
          HttpSession session){
         //do stuff
  }
  </code></pre>
  
  <p>The problem I'm having is if a string is passed into the <code>trackingNumber</code> field, the error message is not nice.</p>
  
  <blockquote>
    <p>Failed to convert property value of type 'java.lang.String' to required type 'java.math.BigDecimal' for property 'records[0].trackingNumber'; nested exception is java.lang.NumberFormatException</p>
    
    <p>Failed to convert property value of type 'java.lang.String' to required type 'java.math.BigDecimal' for property 'trackingNumber'; nested exception is java.lang.NumberFormatException</p>
  </blockquote>
  
  <p>One other potential complication is I'm not using Spring form since I'm trying to do some ajax submissions.  This is how I'm submitting the data:</p>
  
  <pre><code>function collectFormData(fields) {
      var data = {};
  
      //myFormData
      data["trackingNumber"] = &lt;&lt;some value here&gt;&gt;;
  
      for (var i = 0; i &lt; fields.length; i++) {
          data["records["+i+"].trackingNumber"] = &lt;&lt;some value&gt;&gt;; 
          //some more data to submit for child records
      }
      return data;
  }
  
  var mData = collectFormData(aSelectedRows);
  if (aSelectedRows.length&gt; 0) {
      $.post('call_controller_save', mData, function(response) {
       if (response.status === 'FAIL') {
           displayError(response);
       } else {
          //SAVE SUCCESSFUL
          $('#successMsgs').append("Data Saved");
      }, 'json');
  } 
  </code></pre>
  
  <p>I've tried changing <code>trackingNumber</code>'s data type to <code>String</code> and wrote a custom <code>ConstraintValidator&lt;CheckNumeric, String&gt;</code>.  It does the trick... I can put in a custom message via <code>ValidationMessages.properties</code>, but I would like to keep the models true to the intended data type.  <strong>Is there another way to control the error message and turn it into something nice and user friendly?</strong> </p>
  
  <p>(I also understand the <code>NumberFormatException</code> is most likely happening in data binding, before the validation step?  But I'm still not sure how to go about fixing the default message)</p>
  
  <p><strong>Edit</strong>
  I use the following configuration</p>
  
  <pre><code>&lt;bean class="org.springframework.context.support.ResourceBundleMessageSource"
      id="messageSource"&gt;
      &lt;property name="basenames"&gt;
          &lt;list&gt;
              &lt;value&gt;messages&lt;/value&gt;
              &lt;value&gt;ValidationMessages&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>In each properties file, I have the identical content.</p>
  
  <pre><code>formData.trackingNumber=Invalid format
  </code></pre>
  
  <p>But the custom message is still not getting picked up.  <strong>Question 2:</strong> Should it be <code>formData</code> or <code>myFormData</code>?  I have confusion whether it is the class name or name of the form object used on the jsp page?</p>