Is there a JSON library that can serialize proxy objects?

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

Get into the problem going to Json from persistent objects. The problem is that my constant class is actually Interface and AO proxy this object under the hood. Here is some sample code:

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

Based on 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 event.getClass (). getName () gives:

$ Proxy228

I tried several solutions in various combinations:

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

So far, nothing has worked, and I'm using a multi-threaded workaround. Any suggestions? I am not married to Gson, so if there is an alternative library that can do this, I would be happy to use it.

+3
2

Flex JSON - bean, , , - .

0
0

Source: https://habr.com/ru/post/1743244/


All Articles