Convert byte[] via text/plain to String
Fix #898 When the payload is `byte[]` ensure that the String is the String representation, not the toString() conversion result.
This commit is contained in:
committed by
Ilayaperumal Gopinathan
parent
8f3e448f07
commit
9ea4ff324c
@@ -63,6 +63,16 @@ public class TextPlainConversionTest {
|
||||
assertThat(received.getPayload()).isEqualTo("Foo{name='Bar'}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteArrayConversionOnOutput() throws Exception {
|
||||
testProcessor.output().send(MessageBuilder.withPayload("Bar".getBytes()).build());
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<?> received = ((TestSupportBinder) binderFactory.getBinder(null, MessageChannel.class))
|
||||
.messageCollector().forChannel(testProcessor.output()).poll(1, TimeUnit.SECONDS);
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload()).isEqualTo("Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextPlainConversionOnInputAndOutput() throws Exception {
|
||||
testProcessor.input().send(MessageBuilder.withPayload(new Foo("Bar")).build());
|
||||
|
||||
@@ -64,7 +64,11 @@ public class ObjectStringMessageConverter extends AbstractMessageConverter {
|
||||
|
||||
protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint) {
|
||||
if (payload != null) {
|
||||
return payload.toString();
|
||||
if ((payload instanceof byte[])) {
|
||||
return new String((byte[]) payload, Charset.forName("UTF-8"));
|
||||
} else {
|
||||
return payload.toString();
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user