Skip to content

Commit 07c9c55

Browse files
committed
PayloadArgumentResolver's MessageConversionException includes original payload type
Issue: SPR-14394 (cherry picked from commit f5282bc)
1 parent 0d3a22c commit 07c9c55

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolver.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -106,17 +106,22 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr
106106
}
107107

108108
Class<?> targetClass = parameter.getParameterType();
109-
if (ClassUtils.isAssignable(targetClass, payload.getClass())) {
109+
Class<?> payloadClass = payload.getClass();
110+
if (ClassUtils.isAssignable(targetClass, payloadClass)) {
110111
validate(message, parameter, payload);
111112
return payload;
112113
}
113114
else {
114-
payload = (this.converter instanceof SmartMessageConverter ?
115-
((SmartMessageConverter) this.converter).fromMessage(message, targetClass, parameter) :
116-
this.converter.fromMessage(message, targetClass));
115+
if (this.converter instanceof SmartMessageConverter) {
116+
SmartMessageConverter smartConverter = (SmartMessageConverter) this.converter;
117+
payload = smartConverter.fromMessage(message, targetClass, parameter);
118+
}
119+
else {
120+
payload = this.converter.fromMessage(message, targetClass);
121+
}
117122
if (payload == null) {
118-
throw new MessageConversionException(message,
119-
"No converter found to convert to " + targetClass + ", message=" + message);
123+
throw new MessageConversionException(message, "Cannot convert from [" +
124+
payloadClass.getName() + "] to [" + targetClass.getName() + "] for " + message);
120125
}
121126
validate(message, parameter, payload);
122127
return payload;

spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/PayloadArgumentResolverTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -132,7 +132,7 @@ public void resolveNonConvertibleParam() throws Exception {
132132
Message<?> notEmptyMessage = MessageBuilder.withPayload(123).build();
133133

134134
thrown.expect(MessageConversionException.class);
135-
thrown.expectMessage("No converter found");
135+
thrown.expectMessage("Cannot convert");
136136
this.resolver.resolveArgument(this.paramAnnotatedRequired, notEmptyMessage);
137137
}
138138

0 commit comments

Comments
 (0)