struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4937) Add SortedSet field support to JSON plugin
Date Mon, 14 May 2018 07:15:00 GMT

    [ https://issues.apache.org/jira/browse/WW-4937?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16473845#comment-16473845
] 

ASF GitHub Bot commented on WW-4937:
------------------------------------

yasserzamani closed pull request #219: WW-4937 Add SortedSet support to JSON plugin
URL: https://github.com/apache/struts/pull/219
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/plugins/json/src/main/java/org/apache/struts2/json/JSONPopulator.java b/plugins/json/src/main/java/org/apache/struts2/json/JSONPopulator.java
index 67d80f182..ef1ac77bd 100644
--- a/plugins/json/src/main/java/org/apache/struts2/json/JSONPopulator.java
+++ b/plugins/json/src/main/java/org/apache/struts2/json/JSONPopulator.java
@@ -203,8 +203,12 @@ else if (value instanceof List) {
                 newCollection = (Collection) clazz.newInstance();
             } catch (InstantiationException ex) {
                 // fallback if clazz represents an interface or abstract class
-                if (Set.class.isAssignableFrom(clazz)) {
+                if (SortedSet.class.isAssignableFrom(clazz)) {
+                    newCollection = new TreeSet();
+                } else if (Set.class.isAssignableFrom(clazz)) {
                     newCollection = new HashSet();
+                } else if (Queue.class.isAssignableFrom(clazz)) {
+                    newCollection = new ArrayDeque();
                 } else {
                     newCollection = new ArrayList();
                 }
diff --git a/plugins/json/src/test/java/org/apache/struts2/json/JSONPopulatorTest.java b/plugins/json/src/test/java/org/apache/struts2/json/JSONPopulatorTest.java
index 695912ea1..b2101c656 100644
--- a/plugins/json/src/test/java/org/apache/struts2/json/JSONPopulatorTest.java
+++ b/plugins/json/src/test/java/org/apache/struts2/json/JSONPopulatorTest.java
@@ -112,6 +112,31 @@ public void testObjectBean() throws Exception {
         assertEquals(2, bean.getArrayMapField()[0].size());
         assertEquals(new Long(2073501), bean.getArrayMapField()[0].get("id1"));
         assertEquals(new Long(3), bean.getArrayMapField()[0].get("id2"));
+
+        assertEquals(3, bean.getSetField().size());
+        assertEquals(true, bean.getSetField().contains("A"));
+        assertEquals(true, bean.getSetField().contains("B"));
+        assertEquals(true, bean.getSetField().contains("C"));
+
+        assertEquals(3, bean.getSortedSetField().size());
+        assertEquals("A", bean.getSortedSetField().first());
+        assertEquals(true, bean.getSortedSetField().contains("B"));
+        assertEquals("C", bean.getSortedSetField().last());
+
+        assertEquals(3, bean.getNavigableSetField().size());
+        assertEquals("A", bean.getNavigableSetField().first());
+        assertEquals(true, bean.getNavigableSetField().contains("B"));
+        assertEquals("C", bean.getNavigableSetField().last());
+
+        assertEquals(3, bean.getQueueField().size());
+        assertEquals("A", bean.getQueueField().poll());
+        assertEquals("B", bean.getQueueField().poll());
+        assertEquals("C", bean.getQueueField().poll());
+
+        assertEquals(3, bean.getDequeField().size());
+        assertEquals("A", bean.getDequeField().pollFirst());
+        assertEquals("B", bean.getDequeField().pollFirst());
+        assertEquals("C", bean.getDequeField().pollFirst());
     }
 
     public void testObjectBeanWithStrings() throws Exception {
diff --git a/plugins/json/src/test/java/org/apache/struts2/json/WrapperClassBean.java b/plugins/json/src/test/java/org/apache/struts2/json/WrapperClassBean.java
index 379c6c9d1..92f45e1dd 100644
--- a/plugins/json/src/test/java/org/apache/struts2/json/WrapperClassBean.java
+++ b/plugins/json/src/test/java/org/apache/struts2/json/WrapperClassBean.java
@@ -18,8 +18,13 @@
  */
 package org.apache.struts2.json;
 
+import java.util.Deque;
 import java.util.List;
 import java.util.Map;
+import java.util.NavigableSet;
+import java.util.Queue;
+import java.util.Set;
+import java.util.SortedSet;
 
 public class WrapperClassBean {
 
@@ -40,6 +45,11 @@
     private List<Map<String, Long>> listMapField;
     private Map<String, List<Long>> mapListField;
     private Map<String, Long>[] arrayMapField;
+    private Set<String> setField;
+    private SortedSet<String> sortedSetField;
+    private NavigableSet<String> navigableSetField;
+    private Queue<String> queueField;
+    private Deque<String> dequeField;
 
     public List<SimpleValue> getListField() {
         return listField;
@@ -73,6 +83,46 @@ public void setArrayMapField(Map<String, Long>[] arrayMapField) {
         this.arrayMapField = arrayMapField;
     }
 
+    public Set<String> getSetField() {
+        return setField;
+    }
+
+    public void setSetField(Set<String> setField) {
+        this.setField = setField;
+    }
+
+    public SortedSet<String> getSortedSetField() {
+        return sortedSetField;
+    }
+
+    public void setSortedSetField(SortedSet<String> sortedSetField) {
+        this.sortedSetField = sortedSetField;
+    }
+
+    public NavigableSet<String> getNavigableSetField() {
+        return navigableSetField;
+    }
+
+    public void setNavigableSetField(NavigableSet<String> navigableSetField) {
+        this.navigableSetField = navigableSetField;
+    }
+
+    public Queue<String> getQueueField() {
+        return queueField;
+    }
+
+    public void setQueueField(Queue<String> queueField) {
+        this.queueField = queueField;
+    }
+
+    public Deque<String> getDequeField() {
+        return dequeField;
+    }
+
+    public void setDequeField(Deque<String> dequeField) {
+        this.dequeField = dequeField;
+    }
+
     public Boolean getBooleanField() {
         return booleanField;
     }
diff --git a/plugins/json/src/test/resources/org/apache/struts2/json/json-7.txt b/plugins/json/src/test/resources/org/apache/struts2/json/json-7.txt
index 3ee1b612a..58cf448e6 100644
--- a/plugins/json/src/test/resources/org/apache/struts2/json/json-7.txt
+++ b/plugins/json/src/test/resources/org/apache/struts2/json/json-7.txt
@@ -16,5 +16,10 @@
         "listField": [{"value":"1"},{"value":"2"}],
         "listMapField": [{"id1":2073501,"id2":3}],
         "mapListField": {"id1":[1,2,3],"id2":[4,3,2,1]},
-        "arrayMapField": [{"id1":2073501,"id2":3}]
+        "arrayMapField": [{"id1":2073501,"id2":3}],
+        "setField": ["A", "C", "B"],
+        "sortedSetField": ["A", "C", "B"],
+        "navigableSetField": ["A", "B", "C"],
+        "queueField": ["A", "B", "C"],
+        "dequeField": ["A", "B", "C"]
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add SortedSet field support to JSON plugin
> ------------------------------------------
>
>                 Key: WW-4937
>                 URL: https://issues.apache.org/jira/browse/WW-4937
>             Project: Struts 2
>          Issue Type: Improvement
>    Affects Versions: 2.3.34
>            Reporter: Jarek Lipski
>            Priority: Minor
>             Fix For: 2.6
>
>
> Currently when I try to deserialize a bean that contains fields of type SortedSet, I
get the following exception: {{}}
> {code:java}
> java.lang.IllegalArgumentException: argument type mismatch{code}
> This is due to the fact that JSONPopulator does not distinguish between Set and SortedSet
interface.
> This can be fixed by creating a TreeSet for SortedSet fields.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message