title: Java BigDecimal validation
body: <p>Here is property definition</p>
  
  <pre><code>public class Item {
  @Digits(integer=6, fraction=2)
  @DecimalMin("0.00") 
  private BigDecimal goods_cost;
  </code></pre>
  
  <p>and getter/setter</p>
  
  <pre><code>public String getGoods_cost() {
      return goods_cost.toString();
  }
  public void setGoods_cost(String goods_cost) {
      this.goods_cost = new BigDecimal(goods_cost);
  }
  </code></pre>
  
  <p>data came from web page </p>
  
  <pre><code>&lt;td&gt;&lt;form:input path="goods_cost" type="text" size="10" maxlength="20"/&gt;&lt;/td&gt; 
  </code></pre>
  
  <p>If input is valid, like 0.01 or 10.15 or 42 everything works fine but if input is invalid, like -10.00 or 12.333 exception generated. There is the exception </p>
  
  <pre><code>org.apache.jasper.JasperException: java.lang.IllegalArgumentException: source to convert from must be an instance of @javax.validation.constraints.Digits @javax.validation.constraints.DecimalMin java.lang.String; instead it was a java.math.BigDecimal
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:548)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:469)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
  org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
  org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
  org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
  org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  
  root cause
  java.lang.IllegalArgumentException: source to convert from must be an instance of @javax.validation.constraints.Digits @javax.validation.constraints.DecimalMin java.lang.String; instead it was a java.math.BigDecimal
  org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:188)
  org.springframework.validation.AbstractPropertyBindingResult.formatFieldValue(AbstractPropertyBindingResult.java:125)
  org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:232)
  org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:120)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116)
  org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
  org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
  org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
  org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
  org.apache.jsp.WEB_002dINF.jsp.goods_jsp._jspx_meth_form_005finput_005f1(goods_jsp.java:325)
  org.apache.jsp.WEB_002dINF.jsp.goods_jsp._jspService(goods_jsp.java:193)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
  org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
  org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
  org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
  org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  </code></pre>
  
  <p>Please help! What is wrong with it?</p>