Skip to content

Commit faf179f

Browse files
committed
Update BeanAdapter.
1 parent 5170f9e commit faf179f

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
subprojects {
1616
group = 'org.httprpc'
17-
version = '6.3.1'
17+
version = '6.3.2'
1818

1919
repositories {
2020
mavenCentral()

kilo-client/src/main/java/org/httprpc/kilo/beans/BeanAdapter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,11 @@ public static Object adapt(Object value) {
605605

606606
/**
607607
* Coerces a value to a given type. If the value is already an instance of
608-
* the target type, it is returned as is. Otherwise, if the type is one of
609-
* the following, the return value is obtained via an appropriate
610-
* conversion method:
608+
* the target type, it is returned as is. If the target type is
609+
* {@link Void} or {@code void}, {@code null} is returned.
610+
* <p>
611+
* Otherwise, if the target type is one of the following, the return value
612+
* is obtained via an appropriate conversion method:
611613
* <p>
612614
* <ul>
613615
* <li>{@link Byte} or {@code byte}</li>
@@ -757,6 +759,8 @@ public static Object coerceGeneric(Object value, Type type) {
757759
private static Object toRawType(Object value, Class<?> type) {
758760
if (type.isInstance(value)) {
759761
return value;
762+
} else if (type == Void.TYPE || type == Void.class) {
763+
return null;
760764
} else if (type == Byte.TYPE || type == Byte.class) {
761765
if (value == null) {
762766
return (type == Byte.TYPE) ? (byte)0 : null;

kilo-client/src/test/java/org/httprpc/kilo/beans/BeanAdapterTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ public void testInterfaceCoercion() {
203203
assertFalse(testInterface.getNestedBean().getFlag());
204204
}
205205

206+
@Test
207+
public void testVoidCoercion() {
208+
assertNull(BeanAdapter.coerce(1, Void.class));
209+
assertNull(BeanAdapter.coerce(1, Void.TYPE));
210+
}
211+
206212
@Test
207213
public void testPrimitiveCoercion() {
208214
assertEquals((byte)0, BeanAdapter.coerce(null, Byte.TYPE));

0 commit comments

Comments
 (0)