Skip to content

Fix SplitterMH for primitive arrays cast #2964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.integration.support.json.JacksonPresent;
import org.springframework.integration.util.FunctionIterator;
import org.springframework.messaging.Message;
import org.springframework.util.ObjectUtils;

import com.fasterxml.jackson.core.TreeNode;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void setApplySequence(boolean applySequence) {
@Override
@SuppressWarnings("unchecked")
protected final Object handleRequestMessage(Message<?> message) {
Object result = this.splitMessage(message);
Object result = splitMessage(message);
// return null if 'null'
if (result == null) {
return null;
Expand All @@ -87,7 +88,7 @@ protected final Object handleRequestMessage(Message<?> message) {
}
}
else if (result.getClass().isArray()) {
Object[] items = (Object[]) result;
Object[] items = ObjectUtils.toObjectArray(result);
sequenceSize = items.length;
if (reactive) {
flux = Flux.fromArray(items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
public class DefaultSplitterTests {

@Test
public void splitMessageWithArrayPayload() throws Exception {
public void splitMessageWithArrayPayload() {
String[] payload = new String[] { "x", "y", "z" };
Message<String[]> message = MessageBuilder.withPayload(payload).build();
QueueChannel replyChannel = new QueueChannel();
Expand All @@ -75,7 +75,7 @@ public void splitMessageWithArrayPayload() throws Exception {
}

@Test
public void splitMessageWithCollectionPayload() throws Exception {
public void splitMessageWithCollectionPayload() {
List<String> payload = Arrays.asList("x", "y", "z");
Message<List<String>> message = MessageBuilder.withPayload(payload).build();
QueueChannel replyChannel = new QueueChannel();
Expand Down Expand Up @@ -163,20 +163,20 @@ public void splitFlux() {

@Test
public void splitArrayPayloadReactive() {
Message<?> message = new GenericMessage<>(new String[] { "x", "y", "z" });
Message<?> message = new GenericMessage<>(new int[] { 0, 1, 2 });
FluxMessageChannel replyChannel = new FluxMessageChannel();
DefaultMessageSplitter splitter = new DefaultMessageSplitter();
splitter.setOutputChannel(replyChannel);

splitter.handleMessage(message);

Flux<String> testFlux =
Flux<Integer> testFlux =
Flux.from(replyChannel)
.map(Message::getPayload)
.cast(String.class);
.cast(Integer.class);

StepVerifier.create(testFlux)
.expectNext("x", "y", "z")
.expectNext(0, 1, 2)
.then(() ->
((Subscriber<?>) TestUtils.getPropertyValue(replyChannel, "subscribers", List.class).get(0))
.onComplete())
Expand Down