mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-4301 Adds additional use-case to proof the problem exists
This commit is contained in:
@@ -20,7 +20,10 @@
|
||||
*/
|
||||
package org.apache.struts2.json;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -63,4 +66,15 @@ public class JSONUtilTest extends TestCase {
|
||||
// is a
|
||||
// String
|
||||
}
|
||||
|
||||
public void testSerializeListOfList() throws Exception {
|
||||
ListBean bean = new ListBean();
|
||||
// This additional 'listOfLists' pattern should be omitted, but not with current version of JSONUtil
|
||||
List<Pattern> includeProperties = JSONUtil.processIncludePatterns(JSONUtil.asSet("listOfLists,listOfLists\\[\\d+\\]\\[\\d+\\]"), JSONUtil.REGEXP_PATTERN);
|
||||
|
||||
String actual = JSONUtil.serialize(bean, null, new ArrayList<Pattern>(includeProperties), false, false);
|
||||
|
||||
assertEquals("{\"listOfLists\":[[\"1\",\"2\"],[\"3\",\"4\"],[\"5\",\"6\"],[\"7\",\"8\"],[\"9\",\"0\"]]}", actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.apache.struts2.json;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ListBean {
|
||||
|
||||
private List<List<String>> listOfLists;
|
||||
|
||||
public ListBean() {
|
||||
listOfLists = new ArrayList<List<String>>();
|
||||
|
||||
listOfLists.add(Arrays.asList("1", "2"));
|
||||
listOfLists.add(Arrays.asList("3", "4"));
|
||||
listOfLists.add(Arrays.asList("5", "6"));
|
||||
listOfLists.add(Arrays.asList("7", "8"));
|
||||
listOfLists.add(Arrays.asList("9", "0"));
|
||||
}
|
||||
|
||||
public List<List<String>> getListOfLists() {
|
||||
return listOfLists;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user