You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/07/26 09:41:38 UTC

[GitHub] zonghaishang closed pull request #2138: support char[] for generic invoke, #2003

zonghaishang closed pull request #2138: support char[] for generic invoke, #2003
URL: https://github.com/apache/incubator-dubbo/pull/2138
 
 
   

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/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
index 424cead9b1..14a0a79b26 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CompatibleTypeUtils.java
@@ -91,6 +91,19 @@ public static Object compatibleTypeConvert(Object value, Class<?> type) {
                 } catch (ClassNotFoundException e) {
                     throw new RuntimeException(e.getMessage(), e);
                 }
+            } else if (char[].class.equals(type)) {
+                // Process string to char array for generic invoke
+                // See
+                // - https://github.com/apache/incubator-dubbo/issues/2003
+                if (string == null) {
+                    return null;
+                }
+                else {
+                    int len = string.length();
+                    char[] chars = new char[len];
+                    string.getChars(0, len, chars, 0);
+                    return chars;
+                }
             }
         } else if (value instanceof Number) {
             Number number = (Number) value;
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java
index 8c51e0214d..fc18ac77e1 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CompatibleTypeUtilsTest.java
@@ -67,6 +67,17 @@ public void testCompatibleTypeConvert() throws Exception {
 
             result = CompatibleTypeUtils.compatibleTypeConvert("2011-12-11 12:24:12", Date.class);
             assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-11 12:24:12"), (Date) result);
+
+            result = CompatibleTypeUtils.compatibleTypeConvert("ab", char[].class);
+            assertEquals(2, ((char[]) result).length);
+            assertEquals('a', ((char[]) result)[0]);
+            assertEquals('b', ((char[]) result)[1]);
+
+            result = CompatibleTypeUtils.compatibleTypeConvert("", char[].class);
+            assertEquals(0, ((char[]) result).length);
+
+            result = CompatibleTypeUtils.compatibleTypeConvert(null, char[].class);
+            assertEquals(null, result);
         }
 
         {


 

----------------------------------------------------------------
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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org