private ArrayNode mergeArrays(ArrayNode target, ArrayNode source, Stack<String> path) {
        if (source.isEmpty()) {
            return target;
        }
        boolean isSourceIndexed = isIndexedArray(source);
        if (target.isEmpty()) {
            if (isSourceIndexed) {
                return mergeIndexedArrays(target, source, path);
            } else {
                return source;
            }
        }
        boolean isTargetIndexed = isIndexedArray(target);
        if (!isTargetIndexed || !isSourceIndexed) {
            throw new IllegalArgumentException(CANNOT_MERGE_NON_INDEXED_LIST_ERROR_MESSAGE);
        }

        return mergeIndexedArrays(target, source, path);

    }
The utility merges chunks received from a streaming response. The original reference implementation is provided
<a href="https://github.com/epam/ai-dial-sdk/blob/0.10.1/aidial_sdk/utils/merge_chunks.py">here</a>.
server/src/main/java/com/epam/aidial/core/server/util/MergeChunks.java