I want to do something like this - deserialize a class with generic type using Gson. The following code works like a charm.
Type type = new TypeToken<ActionTask<UptimeAction>>() {}.getType();
ActionTask task = (ActionTask) gson.fromJson(json, type);
But what if the type is provided as a String? I imagine something like the following.
String className = "UptimeAction";
Type type = ... // get the type somehow
ActionTask task = (ActionTask) gson.fromJson(json, type);
Is this possible at all?
Aucun commentaire:
Enregistrer un commentaire