Don't treat byte[] or collections in a special way.
This commit is contained in:
committed by
Oleg Zhurakousky
parent
0acff2b1d3
commit
b1d9890e0c
@@ -20,7 +20,6 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -29,7 +28,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -699,22 +697,25 @@ public class BeanFactoryAwareFunctionRegistry
|
||||
convertedValue = this.convertValueToMessage(message, enricher, acceptedContentType);
|
||||
}
|
||||
}
|
||||
else if (value instanceof byte[]) {
|
||||
convertedValue = MessageBuilder.withPayload(value)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, acceptedContentType).build();
|
||||
}
|
||||
else if (value instanceof Iterable || ObjectUtils.isArray(value)) {
|
||||
boolean isArray = ObjectUtils.isArray(value);
|
||||
if (isArray) {
|
||||
value = Arrays.asList((Object[]) value);
|
||||
}
|
||||
AtomicReference<List<Message>> messages = new AtomicReference<List<Message>>(new ArrayList<>());
|
||||
((Iterable) value).forEach(element ->
|
||||
messages.get()
|
||||
.add((Message) convertOutputValueIfNecessary(element, enricher, acceptedContentType
|
||||
.toString())));
|
||||
convertedValue = messages.get();
|
||||
}
|
||||
//<<<<<<< HEAD
|
||||
// else if (value instanceof byte[]) {
|
||||
// convertedValue = MessageBuilder.withPayload(value)
|
||||
// .setHeader(MessageHeaders.CONTENT_TYPE, acceptedContentType).build();
|
||||
// }
|
||||
// else if (value instanceof Iterable || ObjectUtils.isArray(value)) {
|
||||
// boolean isArray = ObjectUtils.isArray(value);
|
||||
// if (isArray) {
|
||||
// value = Arrays.asList((Object[]) value);
|
||||
// }
|
||||
// AtomicReference<List<Message>> messages = new AtomicReference<List<Message>>(new ArrayList<>());
|
||||
// ((Iterable) value).forEach(element ->
|
||||
// messages.get()
|
||||
// .add((Message) convertOutputValueIfNecessary(element, enricher, acceptedContentType
|
||||
// .toString())));
|
||||
// convertedValue = messages.get();
|
||||
// }
|
||||
//=======
|
||||
//>>>>>>> Don't treat byte[] or collections in a special way.
|
||||
else {
|
||||
convertedValue = this.convertValueToMessage(value, enricher, acceptedContentType);
|
||||
}
|
||||
|
||||
@@ -336,6 +336,14 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(composed).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byteArrayNoSpecialHandling() throws Exception {
|
||||
FunctionCatalog catalog = this.configureCatalog(ByteArrayFunction.class);
|
||||
FunctionInvocationWrapper function = catalog.lookup("beanFactoryAwareFunctionRegistryTests.ByteArrayFunction", "application/json");
|
||||
assertThat(function).isNotNull();
|
||||
Message<byte[]> result = (Message<byte[]>) function.apply(MessageBuilder.withPayload("hello".getBytes()).setHeader(MessageHeaders.CONTENT_TYPE, "application/octet-stream").build());
|
||||
assertThat(result.getPayload()).isEqualTo("\"b2xsZWg=\"".getBytes());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@@ -689,4 +697,19 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
@Component
|
||||
public static class ByteArrayFunction implements Function<byte[], byte[]> {
|
||||
|
||||
@Override
|
||||
public byte[] apply(byte[] bytes) {
|
||||
byte[] result = new byte[bytes.length];
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
result[i] = bytes[bytes.length - i - 1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user