@Udf
  public String concat(@UdfParameter final String... jsonStrings) {
    if (jsonStrings == null) {
      return null;
    }
    final List<JsonNode> nodes = new ArrayList<>(jsonStrings.length);
    boolean allObjects = true;
    for (final String jsonString : jsonStrings) {
      if (jsonString == null) {
        return null;
      }

      final JsonNode node = UdfJsonMapper.parseJson(jsonString);
      if (node.isMissingNode()) {
        return null;
      }

      if (allObjects && !node.isObject()) {
        allObjects = false;
      }

      nodes.add(node);
    }

    JsonNode result = nodes.get(0);

    if (allObjects) {
      for (int i = 1; i < nodes.size(); i++) {
        result = concatObjects((ObjectNode) result, (ObjectNode) nodes.get(i));
      }
    } else {
      for (int i = 1; i < nodes.size(); i++) {
        result = concatArrays(toArrayNode(result), toArrayNode(nodes.get(i)));
      }
    }

    return UdfJsonMapper.writeValueAsJson(result);
  }
@Test
  public void shouldMergeNestedArrays() {
    // When:
    final String result = udf.concat("[1, [2]]", "[[[3]], [[[4]]]]");

    // Then:
    assertEquals("[1,[2],[[3]],[[[4]]]]", result);
  }