You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2016/05/13 06:06:55 UTC
struts git commit: WW-4627 Adds unit test to confirm the issue
Repository: struts
Updated Branches:
refs/heads/support-2-3 9bcd1bc9f -> 9f2cae2f1
WW-4627 Adds unit test to confirm the issue
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/9f2cae2f
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/9f2cae2f
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/9f2cae2f
Branch: refs/heads/support-2-3
Commit: 9f2cae2f1e54d43d71d49963c82bff7a4be31511
Parents: 9bcd1bc
Author: Lukasz Lenart <lu...@apache.org>
Authored: Fri May 13 08:00:04 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Fri May 13 08:00:04 2016 +0200
----------------------------------------------------------------------
.../org/apache/struts2/json/JSONWriterTest.java | 37 ++++++++++++++++++++
.../struts2/json/jsonwriter-write-bean-04.txt | 16 +++++++++
2 files changed, 53 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/9f2cae2f/plugins/json/src/test/java/org/apache/struts2/json/JSONWriterTest.java
----------------------------------------------------------------------
diff --git a/plugins/json/src/test/java/org/apache/struts2/json/JSONWriterTest.java b/plugins/json/src/test/java/org/apache/struts2/json/JSONWriterTest.java
index 88c888c..2a9d733 100644
--- a/plugins/json/src/test/java/org/apache/struts2/json/JSONWriterTest.java
+++ b/plugins/json/src/test/java/org/apache/struts2/json/JSONWriterTest.java
@@ -7,7 +7,9 @@ import org.junit.Test;
import java.net.URL;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.TimeZone;
@@ -90,6 +92,41 @@ public class JSONWriterTest extends StrutsTestCase{
TestUtils.assertEquals(JSONWriter.class.getResource("jsonwriter-write-bean-02.txt"), json);
}
+ @Test
+ public void testWriteBeanWithList() throws Exception {
+ BeanWithList bean1 = new BeanWithList();
+ bean1.setStringField("str");
+ bean1.setBooleanField(true);
+ bean1.setCharField('s');
+ bean1.setDoubleField(10.1);
+ bean1.setFloatField(1.5f);
+ bean1.setIntField(10);
+ bean1.setLongField(100);
+ bean1.setEnumField(AnEnum.ValueA);
+ bean1.setEnumBean(AnEnumBean.Two);
+ List<String> errors = new ArrayList<String>();
+ errors.add("Field is required");
+ bean1.setErrors(errors);
+
+ JSONWriter jsonWriter = new JSONWriter();
+ jsonWriter.setEnumAsBean(false);
+ jsonWriter.setIgnoreHierarchy(false);
+ String json = jsonWriter.write(bean1);
+ TestUtils.assertEquals(JSONWriter.class.getResource("jsonwriter-write-bean-04.txt"), json);
+ }
+
+ private class BeanWithList extends Bean {
+ private List<String> errors;
+
+ public List<String> getErrors() {
+ return errors;
+ }
+
+ public void setErrors(List<String> errors) {
+ this.errors = errors;
+ }
+ }
+
private class AnnotatedBean extends Bean{
private URL url;
http://git-wip-us.apache.org/repos/asf/struts/blob/9f2cae2f/plugins/json/src/test/resources/org/apache/struts2/json/jsonwriter-write-bean-04.txt
----------------------------------------------------------------------
diff --git a/plugins/json/src/test/resources/org/apache/struts2/json/jsonwriter-write-bean-04.txt b/plugins/json/src/test/resources/org/apache/struts2/json/jsonwriter-write-bean-04.txt
new file mode 100644
index 0000000..41f0b81
--- /dev/null
+++ b/plugins/json/src/test/resources/org/apache/struts2/json/jsonwriter-write-bean-04.txt
@@ -0,0 +1,16 @@
+{
+ "bigDecimal":null,
+ "bigInteger":null,
+ "booleanField":true,
+ "byteField":0,
+ "charField":"s",
+ "doubleField":10.1,
+ "enumBean":"Two",
+ "enumField":"ValueA",
+ "errors":["Field is required"],
+ "floatField":1.5,
+ "intField":10,
+ "longField":100,
+ "objectField":null,
+ "stringField":"str"
+}