Example usage for org.springframework.beans ConversionNotSupportedException getValue

List of usage examples for org.springframework.beans ConversionNotSupportedException getValue

Introduction

In this page you can find the example usage for org.springframework.beans ConversionNotSupportedException getValue.

Prototype

@Override
@Nullable
public Object getValue() 

Source Link

Document

Return the offending value (may be null ).

Usage

From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractController.java

@ExceptionHandler(ConversionNotSupportedException.class)
@ResponseBody//from   w w w.j  a v  a 2  s .co m
public UnspecifiedCts2Exception handleException(HttpServletResponse response, HttpServletRequest request,
        ConversionNotSupportedException ex) {
    int status = HttpServletResponse.SC_BAD_REQUEST;
    response.setStatus(status);

    Class<?> requiredType = ex.getRequiredType();
    String typeName = requiredType.getSimpleName();
    String value = ex.getValue().toString();

    String possibleValues = "";

    if (requiredType.isEnum()) {
        StringBuilder sb = new StringBuilder();
        sb.append(" Possible values include: ");

        Object[] values = requiredType.getEnumConstants();

        sb.append(StringUtils.join(values, ", "));

        possibleValues = sb.toString();
    }

    return ExceptionFactory.createUnknownException(
            "Cannot convert value " + value + " to the type " + typeName + "." + possibleValues,
            getUrlString(request), getParameterString(request));
}