use of org.springframework.beans.TypeMismatchException in project spring-framework by spring-projects.
the class MarshallingMessageConverter method convertFromInternal.
@Override
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint) {
Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required");
try {
Source source = getSource(message.getPayload());
Object result = this.unmarshaller.unmarshal(source);
if (!targetClass.isInstance(result)) {
throw new TypeMismatchException(result, targetClass);
}
return result;
} catch (Exception ex) {
throw new MessageConversionException(message, "Could not unmarshal XML: " + ex.getMessage(), ex);
}
}
use of org.springframework.beans.TypeMismatchException in project spring-framework by spring-projects.
the class ResponseStatusExceptionResolverTests method nestedException.
// SPR-12903
@Test
public void nestedException() throws Exception {
Exception cause = new StatusCodeAndReasonMessageException();
TypeMismatchException ex = new TypeMismatchException("value", ITestBean.class, cause);
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertResolved(mav, 410, null);
}
use of org.springframework.beans.TypeMismatchException in project spring-framework by spring-projects.
the class ResponseEntityExceptionHandlerTests method typeMismatch.
@Test
public void typeMismatch() {
Exception ex = new TypeMismatchException("foo", String.class);
testException(ex);
}
use of org.springframework.beans.TypeMismatchException in project spring-framework by spring-projects.
the class DefaultHandlerExceptionResolverTests method handleTypeMismatch.
@Test
public void handleTypeMismatch() {
TypeMismatchException ex = new TypeMismatchException("foo", String.class);
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 400, response.getStatus());
}
use of org.springframework.beans.TypeMismatchException in project gocd by gocd.
the class GoConfigFieldLoader method setValue.
private void setValue(Object val) {
try {
ConfigAttributeValue configAttributeValue = field.getType().getAnnotation(ConfigAttributeValue.class);
if (configAttributeValue != null) {
if (val != null || configAttributeValue.createForNull()) {
Constructor<?> constructor = field.getType().getConstructor(String.class);
field.set(instance, constructor.newInstance(new Object[] { val }));
}
} else if (val != null) {
Object convertedValue = typeConverter.convertIfNecessary(val, field.getType());
field.set(instance, convertedValue);
}
} catch (IllegalAccessException e) {
throw bomb("Error setting configField: " + field.getName(), e);
} catch (TypeMismatchException e) {
final String message = format("Could not set value [{0}] on Field [{1}] of type [{2}] ", val, field.getName(), field.getType());
throw bomb(message, e);
} catch (NoSuchMethodException e) {
throw bomb("Error setting configField: " + field.getName() + " as " + field.getType(), e);
} catch (InstantiationException e) {
throw bomb("Error creating configAttribute: " + field.getName() + " as " + field.getType(), e);
} catch (InvocationTargetException e) {
throw bomb("Error creating configAttribute: " + field.getName() + " as " + field.getType(), e);
}
}
Aggregations