I am using the json google library. we can have this:
Public Class JsonParsing<T> {
private Gson gson;
public JsonParsing(GsonBuilder builder) {
this.gson = builder.create();
}
public T[] fromJsonFromArray(String json, Class<T[]> classOfT) {
return gson.fromJson(json, classOfT);
}
}
How we can create the instance of Class<T[]>
in order to pass to this method?
Addenda:
I tried to create a generic method :
public <T> T[] fromJsonFromArray(String json) {
final Type type = new TypeToken<T[]>(){}.getType();
return gson.fromJson(json, classOfT);
}
It seems that I can not have a T[]
as return. Then how can I parse an array of data with json format?
Note: It is possible to do it in a non-generic way.
Couldn't we have any generic solution?