Search in sources :

Example 1 with ConversionNotSupportedException

use of cn.taketoday.beans.ConversionNotSupportedException in project today-framework by TAKETODAY.

the class ResponseEntityExceptionHandlerTests method conversionNotSupported.

@Test
public void conversionNotSupported() {
    Exception ex = new ConversionNotSupportedException(new Object(), Object.class, null);
    testException(ex);
}
Also used : MissingRequestPartException(cn.taketoday.web.bind.resolver.MissingRequestPartException) MissingPathVariableException(cn.taketoday.web.bind.MissingPathVariableException) ServletException(jakarta.servlet.ServletException) HttpRequestMethodNotSupportedException(cn.taketoday.web.HttpRequestMethodNotSupportedException) MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) RequestBindingException(cn.taketoday.web.bind.RequestBindingException) ConversionNotSupportedException(cn.taketoday.beans.ConversionNotSupportedException) HttpMessageNotReadableException(cn.taketoday.http.converter.HttpMessageNotReadableException) TypeMismatchException(cn.taketoday.beans.TypeMismatchException) HttpMediaTypeNotSupportedException(cn.taketoday.web.HttpMediaTypeNotSupportedException) HttpMediaTypeNotAcceptableException(cn.taketoday.web.HttpMediaTypeNotAcceptableException) BindException(cn.taketoday.validation.BindException) AsyncRequestTimeoutException(cn.taketoday.web.context.async.AsyncRequestTimeoutException) HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) MethodArgumentNotValidException(cn.taketoday.web.bind.MethodArgumentNotValidException) ConversionNotSupportedException(cn.taketoday.beans.ConversionNotSupportedException) Test(org.junit.jupiter.api.Test)

Example 2 with ConversionNotSupportedException

use of cn.taketoday.beans.ConversionNotSupportedException in project today-framework by TAKETODAY.

the class AbstractNamedValueResolvingStrategy method resolveArgument.

@Nullable
@Override
public final Object resolveArgument(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
    MethodParameter methodParameter = resolvable.getParameter();
    NamedValueInfo namedValueInfo = getNamedValueInfo(resolvable);
    MethodParameter nestedParameter = methodParameter.nestedIfOptional();
    Object arg;
    if (namedValueInfo.nameEmbedded) {
        Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
        if (resolvedName == null) {
            throw new IllegalArgumentException("Specified name must not resolve to null: [" + namedValueInfo.name + "]");
        }
        arg = resolveName(resolvedName.toString(), resolvable, context);
    } else {
        arg = resolveName(namedValueInfo.name, resolvable, context);
    }
    if (arg == null) {
        if (namedValueInfo.defaultValue != null) {
            arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
        } else if (namedValueInfo.required && !nestedParameter.isOptional()) {
            handleMissingValue(namedValueInfo.name, nestedParameter, context);
        }
        arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());
    } else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
        arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
    }
    BindingContext bindingContext = context.getBindingContext();
    if (bindingContext != null) {
        WebDataBinder binder = bindingContext.createBinder(context, namedValueInfo.name);
        try {
            arg = binder.convertIfNecessary(arg, methodParameter.getParameterType(), methodParameter);
        } catch (ConversionNotSupportedException ex) {
            throw new MethodArgumentConversionNotSupportedException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
        } catch (TypeMismatchException ex) {
            throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
        }
        // Check for null value after conversion of incoming argument value
        if (arg == null && namedValueInfo.defaultValue == null && namedValueInfo.required && !nestedParameter.isOptional()) {
            handleMissingValueAfterConversion(namedValueInfo.name, nestedParameter, context);
        }
    }
    handleResolvedValue(arg, namedValueInfo.name, resolvable, context);
    return arg;
}
Also used : WebDataBinder(cn.taketoday.web.bind.WebDataBinder) MethodArgumentTypeMismatchException(cn.taketoday.web.handler.method.MethodArgumentTypeMismatchException) NamedValueInfo(cn.taketoday.web.handler.method.NamedValueInfo) TypeMismatchException(cn.taketoday.beans.TypeMismatchException) MethodArgumentTypeMismatchException(cn.taketoday.web.handler.method.MethodArgumentTypeMismatchException) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) MethodParameter(cn.taketoday.core.MethodParameter) BindingContext(cn.taketoday.web.BindingContext) MethodArgumentConversionNotSupportedException(cn.taketoday.web.handler.method.MethodArgumentConversionNotSupportedException) ConversionNotSupportedException(cn.taketoday.beans.ConversionNotSupportedException) MethodArgumentConversionNotSupportedException(cn.taketoday.web.handler.method.MethodArgumentConversionNotSupportedException) Nullable(cn.taketoday.lang.Nullable)

Example 3 with ConversionNotSupportedException

use of cn.taketoday.beans.ConversionNotSupportedException in project today-infrastructure by TAKETODAY.

the class AbstractNamedValueResolvingStrategy method resolveArgument.

@Nullable
@Override
public final Object resolveArgument(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
    MethodParameter methodParameter = resolvable.getParameter();
    NamedValueInfo namedValueInfo = getNamedValueInfo(resolvable);
    MethodParameter nestedParameter = methodParameter.nestedIfOptional();
    Object arg;
    if (namedValueInfo.nameEmbedded) {
        Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
        if (resolvedName == null) {
            throw new IllegalArgumentException("Specified name must not resolve to null: [" + namedValueInfo.name + "]");
        }
        arg = resolveName(resolvedName.toString(), resolvable, context);
    } else {
        arg = resolveName(namedValueInfo.name, resolvable, context);
    }
    if (arg == null) {
        if (namedValueInfo.defaultValue != null) {
            arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
        } else if (namedValueInfo.required && !nestedParameter.isOptional()) {
            handleMissingValue(namedValueInfo.name, nestedParameter, context);
        }
        arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());
    } else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
        arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
    }
    BindingContext bindingContext = context.getBindingContext();
    if (bindingContext != null) {
        WebDataBinder binder = bindingContext.createBinder(context, namedValueInfo.name);
        try {
            arg = binder.convertIfNecessary(arg, methodParameter.getParameterType(), methodParameter);
        } catch (ConversionNotSupportedException ex) {
            throw new MethodArgumentConversionNotSupportedException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
        } catch (TypeMismatchException ex) {
            throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
        }
        // Check for null value after conversion of incoming argument value
        if (arg == null && namedValueInfo.defaultValue == null && namedValueInfo.required && !nestedParameter.isOptional()) {
            handleMissingValueAfterConversion(namedValueInfo.name, nestedParameter, context);
        }
    }
    handleResolvedValue(arg, namedValueInfo.name, resolvable, context);
    return arg;
}
Also used : WebDataBinder(cn.taketoday.web.bind.WebDataBinder) MethodArgumentTypeMismatchException(cn.taketoday.web.handler.method.MethodArgumentTypeMismatchException) NamedValueInfo(cn.taketoday.web.handler.method.NamedValueInfo) TypeMismatchException(cn.taketoday.beans.TypeMismatchException) MethodArgumentTypeMismatchException(cn.taketoday.web.handler.method.MethodArgumentTypeMismatchException) ResolvableMethodParameter(cn.taketoday.web.handler.method.ResolvableMethodParameter) MethodParameter(cn.taketoday.core.MethodParameter) BindingContext(cn.taketoday.web.BindingContext) MethodArgumentConversionNotSupportedException(cn.taketoday.web.handler.method.MethodArgumentConversionNotSupportedException) ConversionNotSupportedException(cn.taketoday.beans.ConversionNotSupportedException) MethodArgumentConversionNotSupportedException(cn.taketoday.web.handler.method.MethodArgumentConversionNotSupportedException) Nullable(cn.taketoday.lang.Nullable)

Aggregations

ConversionNotSupportedException (cn.taketoday.beans.ConversionNotSupportedException)3 TypeMismatchException (cn.taketoday.beans.TypeMismatchException)3 MethodParameter (cn.taketoday.core.MethodParameter)2 Nullable (cn.taketoday.lang.Nullable)2 BindingContext (cn.taketoday.web.BindingContext)2 WebDataBinder (cn.taketoday.web.bind.WebDataBinder)2 MethodArgumentConversionNotSupportedException (cn.taketoday.web.handler.method.MethodArgumentConversionNotSupportedException)2 MethodArgumentTypeMismatchException (cn.taketoday.web.handler.method.MethodArgumentTypeMismatchException)2 NamedValueInfo (cn.taketoday.web.handler.method.NamedValueInfo)2 ResolvableMethodParameter (cn.taketoday.web.handler.method.ResolvableMethodParameter)2 HttpMessageNotReadableException (cn.taketoday.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (cn.taketoday.http.converter.HttpMessageNotWritableException)1 BindException (cn.taketoday.validation.BindException)1 HttpMediaTypeNotAcceptableException (cn.taketoday.web.HttpMediaTypeNotAcceptableException)1 HttpMediaTypeNotSupportedException (cn.taketoday.web.HttpMediaTypeNotSupportedException)1 HttpRequestMethodNotSupportedException (cn.taketoday.web.HttpRequestMethodNotSupportedException)1 MethodArgumentNotValidException (cn.taketoday.web.bind.MethodArgumentNotValidException)1 MissingPathVariableException (cn.taketoday.web.bind.MissingPathVariableException)1 MissingRequestParameterException (cn.taketoday.web.bind.MissingRequestParameterException)1 RequestBindingException (cn.taketoday.web.bind.RequestBindingException)1