Skip to content

Commit e4f0770

Browse files
committed
Ensure that Key annotations are respected for proxy instances.
1 parent 41cdadb commit e4f0770

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ private BeanAdapter(Object bean, HashMap<Class<?>, HashMap<String, Method>> acce
175175

176176
Class<?> type = bean.getClass();
177177

178+
if (Proxy.class.isAssignableFrom(type)) {
179+
Class<?>[] interfaces = type.getInterfaces();
180+
181+
if (interfaces.length == 0) {
182+
throw new IllegalArgumentException();
183+
}
184+
185+
type = interfaces[0];
186+
}
187+
178188
accessors = accessorCache.get(type);
179189

180190
if (accessors == null) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,13 @@ public void testDescribe() {
188188
structures.get(TestBean.NestedBean.class)
189189
);
190190
}
191+
192+
@Test
193+
public void testInterfaceKey() {
194+
TestInterface testInterface = BeanAdapter.adapt(mapOf(entry("i", 10)), TestInterface.class);
195+
196+
Map<String, ?> map = new BeanAdapter(testInterface);
197+
198+
Assertions.assertEquals(10, map.get("i"));
199+
}
191200
}

0 commit comments

Comments
 (0)