use of org.springframework.beans.ConversionNotSupportedException in project spring-framework by spring-projects.
the class DefaultHandlerExceptionResolverTests method handleConversionNotSupportedException.
@Test
public void handleConversionNotSupportedException() throws Exception {
ConversionNotSupportedException ex = new ConversionNotSupportedException(new Object(), String.class, new Exception());
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertThat(mav).as("No ModelAndView returned").isNotNull();
assertThat(mav.isEmpty()).as("No Empty ModelAndView returned").isTrue();
assertThat(response.getStatus()).as("Invalid status code").isEqualTo(500);
// SPR-9653
assertThat(request.getAttribute("jakarta.servlet.error.exception")).isSameAs(ex);
}
use of org.springframework.beans.ConversionNotSupportedException in project alien4cloud by alien4cloud.
the class AbstractTypeNodeParser method parseAndSetValue.
protected void parseAndSetValue(BeanWrapper target, String key, Node valueNode, ParsingContextExecution context, MappingTarget mappingTarget) {
// let's store the parent in the context for future use
context.setParent(target.getWrappedInstance());
if (mappingTarget.getPath().equals("null")) {
// if the path is null, we just to do nothing with the stuff
return;
}
Entry<BeanWrapper, String> entry = findWrapperPropertyByPath(context.getRoot(), target, mappingTarget.getPath());
BeanWrapper realTarget = entry.getKey();
String propertyName = entry.getValue();
Object value = ((INodeParser<?>) mappingTarget.getParser()).parse(valueNode, context);
ParsingContextExecution.setParent(target, value);
if (!propertyName.equals("void")) {
// property named 'void' means : process the parsing but do not set anything
try {
realTarget.setPropertyValue(propertyName, value);
} catch (ConversionNotSupportedException e) {
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.SYNTAX_ERROR, "Invalid yaml type for property", valueNode.getStartMark(), "", valueNode.getEndMark(), toscaType));
} catch (NotWritablePropertyException e) {
log.warn("Error while setting property for yaml parsing.", e);
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.ALIEN_MAPPING_ERROR, "Invalid definition for type", valueNode.getStartMark(), e.getPropertyName(), valueNode.getEndMark(), toscaType));
}
}
if (mappingTarget instanceof KeyValueMappingTarget) {
KeyValueMappingTarget kvmt = (KeyValueMappingTarget) mappingTarget;
BeanWrapper keyBeanWrapper = realTarget;
try {
if (!(keyBeanWrapper.getPropertyValue(kvmt.getKeyPath()) != null && propertyName.equals(key))) {
keyBeanWrapper.setPropertyValue(kvmt.getKeyPath(), key);
}
} catch (ConversionNotSupportedException e) {
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.SYNTAX_ERROR, "Invalid yaml type for property", valueNode.getStartMark(), "", valueNode.getEndMark(), toscaType));
} catch (NotWritablePropertyException e) {
log.warn("Error while setting key to property for yaml parsing.", e);
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.ALIEN_MAPPING_ERROR, "Invalid definition for type", valueNode.getStartMark(), e.getPropertyName(), valueNode.getEndMark(), toscaType));
}
}
}
use of org.springframework.beans.ConversionNotSupportedException in project spring-framework by spring-projects.
the class ResponseEntityExceptionHandlerTests method conversionNotSupported.
@Test
public void conversionNotSupported() {
Exception ex = new ConversionNotSupportedException(new Object(), Object.class, null);
testException(ex);
}
use of org.springframework.beans.ConversionNotSupportedException in project spring-framework by spring-projects.
the class AbstractNamedValueMethodArgumentResolver method resolveArgument.
@Override
@Nullable
public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
MethodParameter nestedParameter = parameter.nestedIfOptional();
Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
if (resolvedName == null) {
throw new IllegalArgumentException("Specified name must not resolve to null: [" + namedValueInfo.name + "]");
}
Object arg = resolveName(resolvedName.toString(), nestedParameter, webRequest);
if (arg == null) {
if (namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
} else if (namedValueInfo.required && !nestedParameter.isOptional()) {
handleMissingValue(namedValueInfo.name, nestedParameter, webRequest);
}
arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());
} else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
}
if (binderFactory != null) {
WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
try {
arg = binder.convertIfNecessary(arg, parameter.getParameterType(), parameter);
} catch (ConversionNotSupportedException ex) {
throw new MethodArgumentConversionNotSupportedException(arg, ex.getRequiredType(), namedValueInfo.name, parameter, ex.getCause());
} catch (TypeMismatchException ex) {
throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(), namedValueInfo.name, parameter, 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, webRequest);
}
}
handleResolvedValue(arg, namedValueInfo.name, parameter, mavContainer, webRequest);
return arg;
}
Aggregations