3

使用 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 结婚,所以如果有一个替代库可以做到这一点,我会很乐意使用它。

4

2 回答 2

0

Flex JSON应该可以工作——它将使用 bean 属性自省器来拉取对象,并且我假设代理类正确地实现了这些。

于 2010-04-28T22:15:00.250 回答
0

还检查了杰克逊

于 2010-04-30T18:27:35.973 回答