Skip to content

Commit

Permalink
add support for char[] in PropertyElf (#2059)
Browse files Browse the repository at this point in the history
fix #2058
  • Loading branch information
NicolaIsotta committed Sep 15, 2023
1 parent 61ac830 commit 53459ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/zaxxer/hikari/util/PropertyElf.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ else if (paramClass == short.class) {
else if (paramClass == boolean.class || paramClass == Boolean.class) {
writeMethod.invoke(target, Boolean.parseBoolean(propValue.toString()));
}
else if (paramClass.isArray() && char.class.isAssignableFrom(paramClass.getComponentType())) {
writeMethod.invoke(target, propValue.toString().toCharArray());
}
else if (paramClass == String.class) {
writeMethod.invoke(target, propValue.toString());
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/zaxxer/hikari/mocks/TestObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class TestObject
private TestObject testObject;
private String string;
private short shortRaw;
private char[] charArray;

public void setTestObject(TestObject testObject)
{
Expand Down Expand Up @@ -33,4 +34,14 @@ public short getShortRaw() {
public void setShortRaw(short shortRaw) {
this.shortRaw = shortRaw;
}

public void setCharArray(char[] charArray)
{
this.charArray = charArray;
}

public char[] getCharArray()
{
return charArray;
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/zaxxer/hikari/util/PropertyElfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Properties;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.fail;
Expand All @@ -18,10 +19,12 @@ public void setTargetFromProperties() throws Exception
properties.setProperty("string", "aString");
properties.setProperty("testObject", "com.zaxxer.hikari.mocks.TestObject");
properties.setProperty("shortRaw", "1");
properties.setProperty("charArray", "aCharArray");
TestObject testObject = new TestObject();
PropertyElf.setTargetFromProperties(testObject, properties);
assertEquals("aString", testObject.getString());
assertEquals((short) 1, testObject.getShortRaw());
assertArrayEquals("aCharArray".toCharArray(), testObject.getCharArray());
assertEquals(com.zaxxer.hikari.mocks.TestObject.class, testObject.getTestObject().getClass());
assertNotSame(testObject, testObject.getTestObject());
}
Expand Down

0 comments on commit 53459ab

Please sign in to comment.