使用 ActiveObjects 作为我的 ORM 和 Gson 作为我的 JSON 处理器。
遇到从持久对象转到 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() 给出:
$代理228
我尝试了几种不同组合的解决方案:
gsonBuilder.registerTypeAdapter(Venue.class, newVenueSerializer());
Type listType = new TypeToken<Venue>() {}.getType();
到目前为止没有任何效果,我正在使用一种不稳定的逐场解决方法。有什么建议么?我没有和 Gson 结婚,所以如果有一个替代库可以做到这一点,我会很乐意使用它。