Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for char[] in PropertyElf #2059

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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