當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeMismatchException.getValue方法代碼示例

本文整理匯總了Java中org.springframework.beans.TypeMismatchException.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeMismatchException.getValue方法的具體用法?Java TypeMismatchException.getValue怎麽用?Java TypeMismatchException.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.TypeMismatchException的用法示例。


在下文中一共展示了TypeMismatchException.getValue方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleTypeMismatch

import org.springframework.beans.TypeMismatchException; //導入方法依賴的package包/類
@Override
protected ResponseEntity<Object> handleTypeMismatch(final TypeMismatchException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
    logger.info(ex.getClass().getName());
    //
    final String error = ex.getValue() + " value for " + ex.getPropertyName() + " should be of type " + ex.getRequiredType();

    final ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
    return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
 
開發者ID:junneyang,項目名稱:xxproject,代碼行數:10,代碼來源:CustomRestExceptionHandler.java

示例2: handleTypeMismatch

import org.springframework.beans.TypeMismatchException; //導入方法依賴的package包/類
@Override
protected ResponseEntity<Object> handleTypeMismatch(final TypeMismatchException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
	logger.info(ex.getClass().getName());
	//
	final String error = ex.getValue() + " value for " + ex.getPropertyName() + " should be of type " + ex.getRequiredType();

	final AitException AitException = new AitException(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
	return handleExceptionInternal(ex, AitException, headers, AitException.getStatus(), request);
}
 
開發者ID:allianzit,項目名稱:ait-platform,代碼行數:10,代碼來源:AitRestExceptionHandler.java

示例3: shouldHandleException

import org.springframework.beans.TypeMismatchException; //導入方法依賴的package包/類
@Override
public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) {
    SortedApiErrorSet handledErrors = null;
    List<Pair<String, String>> extraDetailsForLogging = new ArrayList<>();

    if (ex instanceof NoHandlerFoundException) {
        handledErrors = singletonSortedSetOf(projectApiErrors.getNotFoundApiError());
    }

    if (ex instanceof TypeMismatchException) {
        TypeMismatchException tme = (TypeMismatchException) ex;
        Map<String, Object> metadata = new LinkedHashMap<>();

        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);

        String badPropName = extractPropertyName(tme);
        String badPropValue = (tme.getValue() == null) ? null : String.valueOf(tme.getValue());
        String requiredTypeNoInfoLeak = extractRequiredTypeNoInfoLeak(tme);

        extraDetailsForLogging.add(Pair.of("bad_property_name", badPropName));
        if (badPropName != null) {
            metadata.put("bad_property_name", badPropName);
        }
        extraDetailsForLogging.add(Pair.of("bad_property_value", String.valueOf(tme.getValue())));
        if (badPropValue != null) {
            metadata.put("bad_property_value", badPropValue);
        }
        extraDetailsForLogging.add(Pair.of("required_type", String.valueOf(tme.getRequiredType())));
        if (requiredTypeNoInfoLeak != null) {
            metadata.put("required_type", requiredTypeNoInfoLeak);
        }
        handledErrors = singletonSortedSetOf(
            new ApiErrorWithMetadata(projectApiErrors.getTypeConversionApiError(), metadata)
        );
    }

    if (ex instanceof ServletRequestBindingException) {
        // Malformed requests can be difficult to track down - add the exception's message to our logging details
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);
        handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError());
    }

    if (ex instanceof HttpMessageConversionException) {
        // Malformed requests can be difficult to track down - add the exception's message to our logging details
        utils.addBaseExceptionMessageToExtraDetailsForLogging(ex, extraDetailsForLogging);

        if (isMissingExpectedContentCase((HttpMessageConversionException) ex)) {
            handledErrors = singletonSortedSetOf(projectApiErrors.getMissingExpectedContentApiError());
        }
        else {
            // NOTE: If this was a HttpMessageNotReadableException with a cause of
            //          com.fasterxml.jackson.databind.exc.InvalidFormatException then we *could* theoretically map
            //          to projectApiErrors.getTypeConversionApiError(). If we ever decide to implement this, then
            //          InvalidFormatException does contain reference to the field that failed to convert - we can
            //          get to it via getPath(), iterating over each path object, and building the full path by
            //          concatenating them with '.'. For now we'll just turn all errors in this category into
            //          projectApiErrors.getMalformedRequestApiError().
            handledErrors = singletonSortedSetOf(projectApiErrors.getMalformedRequestApiError());
        }
    }

    if (ex instanceof HttpMediaTypeNotAcceptableException) {
        handledErrors = singletonSortedSetOf(projectApiErrors.getNoAcceptableRepresentationApiError());
    }

    if (ex instanceof HttpMediaTypeNotSupportedException) {
        handledErrors = singletonSortedSetOf(projectApiErrors.getUnsupportedMediaTypeApiError());
    }

    if (ex instanceof HttpRequestMethodNotSupportedException) {
        handledErrors = singletonSortedSetOf(projectApiErrors.getMethodNotAllowedApiError());
    }

    if (handledErrors != null) {
        return ApiExceptionHandlerListenerResult.handleResponse(handledErrors, extraDetailsForLogging);
    }

    return ApiExceptionHandlerListenerResult.ignoreResponse();
}
 
開發者ID:Nike-Inc,項目名稱:backstopper,代碼行數:80,代碼來源:OneOffSpringFrameworkExceptionHandlerListener.java


注:本文中的org.springframework.beans.TypeMismatchException.getValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。