Spring3 no funciona @válido cuando la solicitud json recibí 400 Error de solicitud incorrecta

Estoy usando el framework Spring3, hibernate validator y jackson.

cuando solicito jsondata al servidor. devolvió 400 Error de solicitud incorrecta.

entonces mis datos son de tipo missmatch.

Cuando solicito el tipo de coincidencia, entonces está funcionando bien.

Mi código de controlador:

@RequestMapping(consumes = MediaType.ALL_VALUE, produces = MediaType.ALL_VALUE,value =
    "doAdd", method = RequestMethod.POST)
@ResponseBody
public Customer doAdd(@RequestBody @Valid Customer inData){
    this.customerService.addData(inData);
    return inData;
}

yMétodo de manejo de errores es:

@ExceptionHandler
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public void ajaxValidationErrorHandle(MethodArgumentNotValidException errors ,
    HttpServletResponse response) throws BusinessException {
    List<String> resErrors = new ArrayList<String>();
    for(ObjectError error : errors.getBindingResult().getAllErrors()){
        resErrors.add(error.getCode());
    }
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    throw new BusinessException("E000001", "VALIDATION");
}

Cliente.java (modelo):

package test.business.model;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Range;

public class Customer {
    @Size(min = 0, max = 3)
    public String id;

    @NotNull
    @Size(min = 1)
    public String name;

    @NotNull
    @Range(min = 10, max = 99)
    public Integer age;

    public String updateTime;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
}

datos json:

1.{"name":"ken","age":11,"updateTime":"2013-06-18"}
2.{"name":"ken","age":"","updateTime":""}
3.{"name":"ken","age":"joe","updateTime":""}

json datos 1 se devuelve normalmente.

Los datos json 2 se devuelven normalmente (detecté MethodArgumentNotValidException customer.age, NotNull).

json data 2 se devuelve 400 Error de solicitud incorrecta. pero espero que el servidor haya devuelto error typeMismatch.int.

@Pavel Horal ¡Muchas gracias!

Podía capturar la HttpMessageNotReadableException y manejarla.

El error maneja los métodos que han cambiado.

    @ExceptionHandler
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public void ajaxValidationErrorHandle(Exception errors , HttpServletResponse response) throws BusinessException {
    if(errors instanceof MethodArgumentNotValidException){
        MethodArgumentNotValidException mane = (MethodArgumentNotValidException)errors;
        for(ObjectError error : mane.getBindingResult().getAllErrors()){
            resErrors.add(error.getCode());
        }
    }
    if(errors instanceof HttpMessageNotReadableException){
        JsonMappingException jme = (JsonMappingException)errors.getCause();
        List<Reference> errorObj = jme.getPath();
        for(Reference r : errorObj){
            System.out.println(r.getFieldName());
        }
    }
・・・

Sin embargo, es lo que se hereda para hacer que la clase base o escribir este código en todos los controladores parezca que no he visto el concepto de diseño de Spring porque se decidió manejar allí para hacer un ExceptionResolver nuevo.

Mi nuevo ExceptionResolver es:

public class OriginalExceptionHandler extends SimpleMappingExceptionResolver {

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) {
    ModelAndView m = null;
    StringBuilder exceptionMessage = new StringBuilder(ajaxDefaultErrorMessage) ;
    if(e instanceof BusinessException){
                   ・・・
    }else if(e instanceof HttpMessageNotReadableException){
        Throwable t = e.getCause();
        if(t instanceof JsonMappingException){
            JsonMappingException jme = (JsonMappingException)t;
            List<Reference> errorObj = jme.getPath();
            for(Reference r : errorObj){
                exceptionMessage.append("VE9999:Unmatched Type Error!!("+r.getFieldName()+")");
            }
        }else{
            exceptionMessage.append(e+"\n"+o.toString());
        }
    }else if(e instanceof MethodArgumentNotValidException){
        MethodArgumentNotValidException mane = (MethodArgumentNotValidException)e;
        for(ObjectError error : mane.getBindingResult().getAllErrors()){
            if(error instanceof FieldError){
                FieldError fe = (FieldError) error;
                exceptionMessage.append("VE0001:Validation Error!!"+fe.getField()+"-"+fe.getDefaultMessage());
            }else{
                exceptionMessage.append("VE0001:Validation Error!!"+error.getDefaultMessage());
            }
        }
    }else{
                 ・・・

Y, he añadido incienso a application-context.xml:

    <bean class="test.core.OriginalExceptionHandler" p:order="1">
    <property name="exceptionMappings">
        <props>
            <prop key="sample.core.BusinessException">
                ExceptionPage
            </prop>
            <prop key="test.core.LoginSessionException">
                LoginSessionException
            </prop>
        </props>
    </property>
    <property name="defaultErrorView" value="error" />
</bean>

Esta forma de pensar correcta?

Gracias,

Respuestas a la pregunta(1)

Su respuesta a la pregunta