File tree Expand file tree Collapse file tree
main/java/com/api/jsonata4java/expressions/functions
test/java/com/api/jsonata4java/expressions/functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ public ArrayNode addObject(ArrayNode result, ObjectNode obj) {
121121 String key = it .next ();
122122 ObjectNode cell = JsonNodeFactory .instance .objectNode ();
123123 cell .set (key , obj .get (key ));
124- result = ( ArrayNode ) append (result , cell );
124+ result = concat (result , cell );
125125 }
126126 return result ;
127127 }
@@ -197,6 +197,7 @@ ArrayNode concat(ArrayNode base, JsonNode appendage) {
197197 result .add (elt );
198198 }
199199 if (appendage .isArray ()) {
200+ result .removeAll ();
200201 for (JsonNode elt : appendage ) {
201202 result .add (elt );
202203 }
Original file line number Diff line number Diff line change 1+ package com .api .jsonata4java .expressions .functions ;
2+
3+ import static com .api .jsonata4java .expressions .utils .Utils .test ;
4+
5+ import org .junit .Test ;
6+
7+ public class SpreadFunctionTest {
8+
9+ @ Test
10+ public void testSpreadForGeneratingCombinationList () throws Exception {
11+ test ("$spread($$.array1 ~> $map(function($v1) {\n " +
12+ " $$.array2 ~> $map(function($v2) {\n " +
13+ " $v1 & '#' & $v2\n " +
14+ " })\n " +
15+ " }))" , "[\n " +
16+ " \" abcd#pp\" ,\n " +
17+ " \" abcd#uu\" ,\n " +
18+ " \" abcd#tt\" ,\n " +
19+ " \" abcd#uu\" ,\n " +
20+ " \" abcd#ww\" ,\n " +
21+ " \" abcd#gg\" ,\n " +
22+ " \" abcd#qq\" ,\n " +
23+ " \" abcd#nn\" ,\n " +
24+ " \" abcd#ff\" ,\n " +
25+ " \" cdef#pp\" ,\n " +
26+ " \" cdef#uu\" ,\n " +
27+ " \" cdef#tt\" ,\n " +
28+ " \" cdef#uu\" ,\n " +
29+ " \" cdef#ww\" ,\n " +
30+ " \" cdef#gg\" ,\n " +
31+ " \" cdef#qq\" ,\n " +
32+ " \" cdef#nn\" ,\n " +
33+ " \" cdef#ff\" ,\n " +
34+ " \" efgh#pp\" ,\n " +
35+ " \" efgh#uu\" ,\n " +
36+ " \" efgh#tt\" ,\n " +
37+ " \" efgh#uu\" ,\n " +
38+ " \" efgh#ww\" ,\n " +
39+ " \" efgh#gg\" ,\n " +
40+ " \" efgh#qq\" ,\n " +
41+ " \" efgh#nn\" ,\n " +
42+ " \" efgh#ff\" ,\n " +
43+ " \" ghij#pp\" ,\n " +
44+ " \" ghij#uu\" ,\n " +
45+ " \" ghij#tt\" ,\n " +
46+ " \" ghij#uu\" ,\n " +
47+ " \" ghij#ww\" ,\n " +
48+ " \" ghij#gg\" ,\n " +
49+ " \" ghij#qq\" ,\n " +
50+ " \" ghij#nn\" ,\n " +
51+ " \" ghij#ff\" ,\n " +
52+ " \" ijkl#pp\" ,\n " +
53+ " \" ijkl#uu\" ,\n " +
54+ " \" ijkl#tt\" ,\n " +
55+ " \" ijkl#uu\" ,\n " +
56+ " \" ijkl#ww\" ,\n " +
57+ " \" ijkl#gg\" ,\n " +
58+ " \" ijkl#qq\" ,\n " +
59+ " \" ijkl#nn\" ,\n " +
60+ " \" ijkl#ff\" ,\n " +
61+ " \" klmn#pp\" ,\n " +
62+ " \" klmn#uu\" ,\n " +
63+ " \" klmn#tt\" ,\n " +
64+ " \" klmn#uu\" ,\n " +
65+ " \" klmn#ww\" ,\n " +
66+ " \" klmn#gg\" ,\n " +
67+ " \" klmn#qq\" ,\n " +
68+ " \" klmn#nn\" ,\n " +
69+ " \" klmn#ff\" ,\n " +
70+ " \" mnop#pp\" ,\n " +
71+ " \" mnop#uu\" ,\n " +
72+ " \" mnop#tt\" ,\n " +
73+ " \" mnop#uu\" ,\n " +
74+ " \" mnop#ww\" ,\n " +
75+ " \" mnop#gg\" ,\n " +
76+ " \" mnop#qq\" ,\n " +
77+ " \" mnop#nn\" ,\n " +
78+ " \" mnop#ff\" \n " +
79+ "]" , null , "{\n " +
80+ " \" array1\" : [\n " +
81+ " \" abcd\" ,\n " +
82+ " \" cdef\" ,\n " +
83+ " \" efgh\" ,\n " +
84+ " \" ghij\" ,\n " +
85+ " \" ijkl\" ,\n " +
86+ " \" klmn\" ,\n " +
87+ " \" mnop\" \n " +
88+ " ],\n " +
89+ " \" array2\" : [\n " +
90+ " \" pp\" ,\n " +
91+ " \" uu\" ,\n " +
92+ " \" tt\" ,\n " +
93+ " \" uu\" ,\n " +
94+ " \" ww\" ,\n " +
95+ " \" gg\" ,\n " +
96+ " \" qq\" ,\n " +
97+ " \" nn\" ,\n " +
98+ " \" ff\" \n " +
99+ " ]\n " +
100+ "}" );
101+ }
102+
103+ }
You can’t perform that action at this time.
0 commit comments