Example #1
0
    private SegmentBlock deserializeBlock(JsonObject json, JsonDeserializationContext context) {
      if (!json.has("actions")) {
        throw new ProtectionParseException("Missing actions identifier");
      }
      SegmentBlock segment = new SegmentBlock();
      segment.types.addAll(
          deserializeAsArray(
              json.get("actions"),
              context,
              new TypeToken<BlockType>() {},
              new TypeToken<List<BlockType>>() {}.getType()));
      json.remove("actions");

      if (json.has("meta")) {
        segment.meta = json.get("meta").getAsInt();
        json.remove("meta");
      }

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

      return segment;
    }
Example #2
0
 private void serializeBlock(
     SegmentBlock segment, JsonObject json, JsonSerializationContext context) {
   json.add("actions", serializeAsElementOrArray(segment.types, context));
   json.addProperty("meta", segment.getMeta());
   if (segment.clientUpdate != null) {
     JsonObject jsonUpdate = new JsonObject();
     jsonUpdate.add("coords", context.serialize(segment.clientUpdate.relativeCoords));
     json.add("clientUpdate", jsonUpdate);
   }
 }