SPR-7263 - TypeMismatchException instead of IllegalArgumentException: argument type mismatch for wrong RequestBody

This commit is contained in:
Arjen Poutsma
2010-06-09 10:35:41 +00:00
parent 2a140addfd
commit 723f94fd0e
4 changed files with 15 additions and 9 deletions

View File

@@ -20,6 +20,7 @@ import java.io.IOException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import org.springframework.beans.TypeMismatchException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
@@ -110,7 +111,11 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException {
Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required");
try {
return this.unmarshaller.unmarshal(source);
Object result = this.unmarshaller.unmarshal(source);
if (!clazz.isInstance(result)) {
throw new TypeMismatchException(result, clazz);
}
return result;
}
catch (UnmarshallingFailureException ex) {
throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex);