-1

I am using GSON to deserialize a JSON string.

mGSON.fromJson(json, mClass)  //mClass == ClassA.class

The problem comes in when using the class below

public class BaseModel<T> {
    String StatusCode, Description;
    T Data;
}

I'd like to do something like this

mGSON.fromJson(json, mClass<DataClass>);

or

mGSON.fromJson(json, (BaseModel<DataClass>).class);

but obviously this doesn't work.

Ashfaque
  • 1,254
  • 1
  • 22
  • 38
MCR
  • 1,633
  • 3
  • 21
  • 36
  • [The documentation](https://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Generic-Types) seems to cover this. – Brian Roach Mar 27 '14 at 15:29

1 Answers1

2

Try and:

mGSON.fromJson(json, new TypeToken<BaseModel<DataClasss>>() {});

See here for more information.

fge
  • 119,121
  • 33
  • 254
  • 329
  • Here is what I ended up using: Type tt = new TypeToken>() {}.getType(); Thank you! – MCR Mar 27 '14 at 15:34