Jacob
unread,Nov 6, 2008, 3:00:48 PM11/6/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-gson
I have a model
class Envelope<T> {
public int version;
public T data;
}
Many many services share the envelope and I want to provide a shared
method for marshalling it. I have tried the following
protected final <T> String buildResult(T result, int version) {
Envelope<T> env = new Envelope<T>();
env.setData(result);
env.setVersion(version);
return new Gson().toJson(env, new TypeToken<Envelope<T>>() {
}.getType());
}
This compiled but fails a runtime with
java.lang.IllegalArgumentException: Type 'T' is not a Class,
ParameterizedType, or GenericArrayType. Can't extract class.
Is there a way to do this without making the type a parameter? I am
more to willing to say my knowledge of generics in Java is weak.
Jacob