Exemplo n.º 1
0
    private <T> JsonElement serializeAsElementOrArray(
        List<T> items, JsonSerializationContext context) {
      if (items.isEmpty()) {
        return null;
      }

      if (items.size() == 1) {
        return context.serialize(items.get(0));
      } else {
        return context.serialize(items);
      }
    }
Exemplo n.º 2
0
 @Override
 public JsonElement serialize(
     PartitionMethodDescExpr src, Type typeOfSrc, JsonSerializationContext context) {
   switch (src.getPartitionType()) {
     case RANGE:
       return context.serialize(src, RangePartition.class);
     case HASH:
       return context.serialize(src, HashPartition.class);
     case LIST:
       return context.serialize(src, ListPartition.class);
     case COLUMN:
       return context.serialize(src, ColumnPartition.class);
     default:
       return null;
   }
 }
 @Override
 public JsonElement serialize(MoveStrategy src, Type typeOfSrc, JsonSerializationContext context) {
   JsonObject result = new JsonObject();
   result.add("type", new JsonPrimitive(src.getClass().getSimpleName()));
   result.add("properties", context.serialize(src, src.getClass()));
   return result;
 }
  @Override
  public JsonElement serialize(
      AssetReference asset, Type typeOfSrc, JsonSerializationContext context) {
    JsonElement jsonAsset = context.serialize(asset.asset, asset.asset.getClass());
    GsonUtils.appendClassProperty(jsonAsset, asset.asset, context);

    JsonObject jsonObject = new JsonObject();
    jsonObject.add("asset", jsonAsset);
    return jsonObject;
  }
Exemplo n.º 5
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);
   }
 }
Exemplo n.º 6
0
 private void serializeItem(
     SegmentItem segment, JsonObject json, JsonSerializationContext context) {
   json.add("actions", serializeAsElementOrArray(segment.types, context));
   json.addProperty("isAdjacent", segment.isAdjacent);
   if (segment.clientUpdate != null) {
     JsonObject jsonUpdate = new JsonObject();
     jsonUpdate.add("coords", context.serialize(segment.clientUpdate.relativeCoords));
     jsonUpdate.addProperty("directional", segment.directionalClientUpdate);
     json.add("clientUpdate", jsonUpdate);
   }
 }
Exemplo n.º 7
0
    private void serializeChatStyle(
        ChatStyle style, JsonObject object, JsonSerializationContext ctx) {
      JsonElement var4 = ctx.serialize(style);

      if (var4.isJsonObject()) {
        JsonObject var5 = (JsonObject) var4;
        Iterator var6 = var5.entrySet().iterator();

        while (var6.hasNext()) {
          Entry var7 = (Entry) var6.next();
          object.add((String) var7.getKey(), (JsonElement) var7.getValue());
        }
      }
    }
Exemplo n.º 8
0
    @Override
    public JsonElement serialize(
        Segment segment, Type typeOfSrc, JsonSerializationContext context) {
      JsonObject json = new JsonObject();
      json.addProperty("class", segment.checkClass.getName());

      if (segment instanceof SegmentSpecialBlock) {
        json.addProperty("type", "specialBlock");
        serializeSpecialBlock((SegmentSpecialBlock) segment, json, context);
      } else {
        if (segment instanceof SegmentBlock) {
          json.addProperty("type", "block");
          serializeBlock((SegmentBlock) segment, json, context);
        } else if (segment instanceof SegmentEntity) {
          json.addProperty("type", "entity");
          serializeEntity((SegmentEntity) segment, json, context);
        } else if (segment instanceof SegmentItem) {
          json.addProperty("type", "item");
          serializeItem((SegmentItem) segment, json, context);
        } else if (segment instanceof SegmentTileEntity) {
          json.addProperty("type", "tileEntity");
          serializeTileEntity((SegmentTileEntity) segment, json, context);
        }

        json.add("flags", serializeAsElementOrArray(segment.flags, context));

        if (segment.condition != null) {
          json.addProperty("condition", segment.condition.toString());
        }
        if (segment.priority != Priority.NORMAL) {
          json.addProperty("priority", segment.priority.toString());
        }
        for (Getter getter : segment.getters) {
          json.add(getter.getName(), context.serialize(getter, Getter.class));
        }
      }

      return json;
    }
Exemplo n.º 9
0
 public JsonElement serialize(T object, Type interfaceType, JsonSerializationContext context) {
   final JsonObject wrapper = new JsonObject();
   wrapper.addProperty("type", object.getClass().getName());
   wrapper.add("data", context.serialize(object));
   return wrapper;
 }