本文整理汇总了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());
}
示例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);
}
示例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();
}