Exemplo n.º 1
1
    private SegmentItem deserializeItem(JsonObject json, JsonDeserializationContext context) {
      if (!json.has("actions")) {
        throw new ProtectionParseException("Missing actions identifier");
      }

      SegmentItem segment = new SegmentItem();

      segment.types.addAll(
          deserializeAsArray(
              json.get("actions"),
              context,
              new TypeToken<ItemType>() {},
              new TypeToken<List<ItemType>>() {}.getType()));
      json.remove("actions");

      if (json.has("isAdjacent")) {
        segment.isAdjacent = json.get("isAdjacent").getAsBoolean();
        json.remove("isAdjacent");
      }

      if (json.has("clientUpdate")) {
        JsonObject jsonClientUpdate = json.get("clientUpdate").getAsJsonObject();
        segment.clientUpdate =
            new ClientBlockUpdate(
                (Volume) context.deserialize(jsonClientUpdate.get("coords"), Volume.class));
        if (jsonClientUpdate.has("directional")) {
          segment.directionalClientUpdate = jsonClientUpdate.get("directional").getAsBoolean();
        }
        json.remove("clientUpdate");
      }

      return segment;
    }