Deserializing JSON into a class with a generic argument using GSON or Jackson
问题 I'm getting responses from my server that look like: { "timestamp" : 1, "some other data": "blah", "result" : { ... } } for a variety of calls. What I want to do client side is: class ServerResponse<T> { long timestamp; T result; } and then deserialize that with GSON or Jackson. I've been unable to do so thanks to type erasure. I've cheated that using subclasses like this: class SpecificResponse extends ServerRequest<SpecificType> {} but that requires a bunch of useless classes to lie around.