Question

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.

Was it helpful?

Solution

Try and:

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

See here for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top