Skip to content

Commit

Permalink
support char[] for generic invoke, apache#2003
Browse files Browse the repository at this point in the history
  • Loading branch information
diecui1202 committed Jul 26, 2018
1 parent 5e82a5e commit c3f31d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public static Object compatibleTypeConvert(Object value, Class<?> type) {
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if (char[].class.equals(type)) {
// #2003, process string to char array for generic invoke
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ 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]);
}

{
Expand Down

0 comments on commit c3f31d2

Please sign in to comment.