views:

92

answers:

2

Using ActiveObjects as my ORM and Gson as my JSON processor.

Ran into a problem going toJson from persisted objects. The problem is that my persisted class is actually an Interface and AO is proxying that object under the hood. Here's some sample code:

    Venue venue = manager.get(Venue.class, id);
    gson.toJson(venue);

Comes up with this exception:

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...

Because venue.getClass().getName() gives:

$Proxy228

I've tried a few solutions in various combinations:

    gsonBuilder.registerTypeAdapter(Venue.class, newVenueSerializer());
    Type listType = new TypeToken<Venue>() {}.getType();

Nothing has worked so far and I'm using a wonky field-by-field workaround. Any suggestions? I'm not married to Gson, so if there's an alternative library that can do this I'd be happy to use it.

A: 

Flex JSON should work - it will use the bean property introspector to pull the object, and I assume the proxy class implements those properly.

stevedbrown
Will give it a shot and report back. Thanks!
gmoore
Doesn't look like the proxy class is implementing any introspectors. If it did, though, you'de have been right. So, you win.
gmoore
Not much of a win... sorry it didn't work.
stevedbrown
A: 

Also check out the Jackson.

Joao