@Override
public ResourceAssignment deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonObject()) {
throw new JsonParseException("Expect a json object, got " + json);
}
JsonObject jsonObj = json.getAsJsonObject();
String name = jsonObj.get("name").getAsString();
Multimap<Discoverable, PartitionReplica> assignments = TreeMultimap.create(DiscoverableComparator.COMPARATOR,
PartitionReplica.COMPARATOR);
JsonArray assignmentsJson = context.deserialize(jsonObj.get("assignments"), JsonArray.class);
for (JsonElement element : assignmentsJson) {
if (!element.isJsonArray()) {
throw new JsonParseException("Expect a json array, got " + element);
}
JsonArray entryJson = element.getAsJsonArray();
if (entryJson.size() != 2) {
throw new JsonParseException("Expect json array of size = 2, got " + entryJson.size());
}
Discoverable key = context.deserialize(entryJson.get(0), Discoverable.class);
PartitionReplica value = context.deserialize(entryJson.get(1), PartitionReplica.class);
assignments.put(key, value);
}