Domanda

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.

È stato utile?

Soluzione

Try and:

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

See here for more information.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top