Skip to content

Commit 120830f

Browse files
committed
WW-4301 Adds additional use-case to proof the problem exists
1 parent dfb2bd3 commit 120830f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

plugins/json/src/test/java/org/apache/struts2/json/JSONUtilTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
*/
2121
package org.apache.struts2.json;
2222

23+
import java.util.ArrayList;
24+
import java.util.List;
2325
import java.util.Map;
26+
import java.util.regex.Pattern;
2427

2528
import junit.framework.TestCase;
2629

@@ -63,4 +66,15 @@ public void testSerializeDeserialize() throws Exception {
6366
// is a
6467
// String
6568
}
69+
70+
public void testSerializeListOfList() throws Exception {
71+
ListBean bean = new ListBean();
72+
// This additional 'listOfLists' pattern should be omitted, but not with current version of JSONUtil
73+
List<Pattern> includeProperties = JSONUtil.processIncludePatterns(JSONUtil.asSet("listOfLists,listOfLists\\[\\d+\\]\\[\\d+\\]"), JSONUtil.REGEXP_PATTERN);
74+
75+
String actual = JSONUtil.serialize(bean, null, new ArrayList<Pattern>(includeProperties), false, false);
76+
77+
assertEquals("{\"listOfLists\":[[\"1\",\"2\"],[\"3\",\"4\"],[\"5\",\"6\"],[\"7\",\"8\"],[\"9\",\"0\"]]}", actual);
78+
}
79+
6680
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.apache.struts2.json;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
public class ListBean {
8+
9+
private List<List<String>> listOfLists;
10+
11+
public ListBean() {
12+
listOfLists = new ArrayList<List<String>>();
13+
14+
listOfLists.add(Arrays.asList("1", "2"));
15+
listOfLists.add(Arrays.asList("3", "4"));
16+
listOfLists.add(Arrays.asList("5", "6"));
17+
listOfLists.add(Arrays.asList("7", "8"));
18+
listOfLists.add(Arrays.asList("9", "0"));
19+
}
20+
21+
public List<List<String>> getListOfLists() {
22+
return listOfLists;
23+
}
24+
}

0 commit comments

Comments
 (0)