fixed a ClassCastException when returning an Iterable that couldn't be cast into Collection from a web-function (e.g. Page)

Resolves #1026
This commit is contained in:
mockxe
2023-04-19 18:58:05 +02:00
committed by Oleg Zhurakousky
parent e3a44c3cf3
commit 3a9c98ef14

View File

@@ -16,10 +16,10 @@
package org.springframework.cloud.function.web.util;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -126,8 +126,8 @@ public final class FunctionWebRequestProcessingHelper {
}
return Mono.from(pResult).map(v -> {
if (v instanceof Iterable) {
List aggregatedResult = (List) ((Collection) v).stream().map(m -> {
if (v instanceof Iterable i) {
List aggregatedResult = (List) StreamSupport.stream(i.spliterator(), false).map(m -> {
return m instanceof Message ? processMessage(responseOkBuilder, (Message<?>) m) : m;
}).collect(Collectors.toList());
return responseOkBuilder.header("content-type", "application/json").body(aggregatedResult);