Description
I am not quite sure, what the original intention of ObjectStringMessageConverter
was, but currently using
ObjectStringMessageConverter converter = new ObjectStringMessageConverter();
Integer payload = 1234;
Message<?> converted = converter.toMessage(payload, null);
assertThat(converted).isNotNull();
fails, as Message<?> converted
is always null
when payload
is anything else than String.class
as AbstractMessageConverter.canConvertTo()
always returns null
due to StringMessageConverter.supports()
https://github.com/spring-projects/spring-framework/blob/80646591367b93d220b9dc0b0a126b203edc140c/spring-messaging/src/main/java/org/springframework/messaging/converter/StringMessageConverter.java#L50-L55
returns false
in this case.
The question arises, whether this is intentional. If ObjectStringMessageConverter.toMessage()
should not be used with anything else than String payload
explicitly throwing an IllegalArgumentException
would probably be a better option. For the opposite case I will provide a PR.