Whoops, it's Grant.class not Group
I'm using an adapter to only serialize/deserialze certain values of the Grant:
public class GrantAdapter implements JsonSerializer<Grant>, JsonDeserializer<Grant> {
@Override
public JsonElement serialize(Grant grant, Type type, JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("id", grant.getDocumentID());
jsonObject.addProperty("rank", grant.getRank().getId());
jsonObject.addProperty("scope", grant.getScope().getId());
jsonObject.addProperty("createdAt", grant.getCreatedAt());
jsonObject.addProperty("duration", grant.getDuration());
return jsonObject;
}
@Override
public Grant deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject object = jsonElement.getAsJsonObject();
String id = object.get("id").getAsString();
String rank = object.get("rank").getAsString();
String scope = object.get("scope").getAsString();
long createdAt = object.get("createdAt").getAsLong();
long duration = object.get("duration").getAsLong();
CorePlugin plugin = CorePlugin.getInstance();
Rank finalRank = plugin.getRankManager().getRankById(rank);
Scope finalScope = plugin.getScopeManager().getScopeById(scope);
if (finalRank == null || finalScope == null) {
return null;
}
return new Grant(id, finalRank, finalScope, createdAt, duration);
}
}