【发布时间】:2010-04-28 19:48:08
【问题描述】:
使用 ActiveObjects 作为我的 ORM 和 Gson 作为我的 JSON 处理器。
从 持久化的对象。问题是我坚持的课程实际上是 一个接口和 AO 在后台代理该对象。这里是 一些示例代码:
Venue venue = manager.get(Venue.class, id);
gson.toJson(venue);
提出了这个例外:
java.lang.UnsupportedOperationException: Expecting parameterized type,
got interface java.lang.reflect.InvocationHandler.
Are you missing the use of TypeToken idiom?
See http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and...
因为 place.getClass().getName() 给出:
$Proxy228
我尝试了几种不同组合的解决方案:
gsonBuilder.registerTypeAdapter(Venue.class, newVenueSerializer());
Type listType = new TypeToken<Venue>() {}.getType();
到目前为止没有任何效果,我正在使用一种不稳定的逐个字段的解决方法。有什么建议么?我没有和 Gson 结婚,所以如果有其他库可以做到这一点,我会很乐意使用它。
【问题讨论】:
标签: java json proxy gson active-objects