velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1827587 - /velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
Date Fri, 23 Mar 2018 17:34:23 GMT
Author: cbrisson
Date: Fri Mar 23 17:34:23 2018
New Revision: 1827587

URL: http://svn.apache.org/viewvc?rev=1827587&view=rev
Log:
fix and improve asList() method

Modified:
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java?rev=1827587&r1=1827586&r2=1827587&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java
Fri Mar 23 17:34:23 2018
@@ -19,8 +19,6 @@ package org.apache.velocity.tools;
  * under the License.
  */
 
-import org.slf4j.LoggerFactory;
-
 import java.io.File;
 import java.lang.reflect.Array;
 import java.net.URL;
@@ -43,6 +41,8 @@ import java.util.Map;
 import java.util.TimeZone;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ConcurrentHashMap;
+import org.apache.commons.lang3.ArrayUtils;
+import org.slf4j.LoggerFactory;
 
 /**
  * Utility methods for parsing or otherwise converting between types.
@@ -848,7 +848,21 @@ public class ConversionUtils
     public static List asList(Object value)
     {
         if (value instanceof List) return (List)value;
-        else if (value.getClass().isArray()) return Arrays.asList(value);
+        else if (value.getClass().isArray())
+        {
+            Class componentClass = value.getClass().getComponentType();
+            if (componentClass.isPrimitive())
+            {
+                if (componentClass.equals(char.class)) value = ArrayUtils.toObject((char[])value);
+                else if (componentClass.equals(long.class)) value = ArrayUtils.toObject((long[])value);
+                else if (componentClass.equals(int.class)) value = ArrayUtils.toObject((int[])value);
+                else if (componentClass.equals(short.class)) value = ArrayUtils.toObject((short[])value);
+                else if (componentClass.equals(byte.class)) value = ArrayUtils.toObject((byte[])value);
+                else if (componentClass.equals(double.class)) value = ArrayUtils.toObject((double[])value);
+                else if (componentClass.equals(float.class)) value = ArrayUtils.toObject((float[])value);
+            }
+            return new ArrayList(Arrays.asList((Object[])value));
+        }
         else
         {
             List ret = new ArrayList();



Mime
View raw message