當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonSerializationContext類代碼示例

本文整理匯總了Java中com.google.gson.JsonSerializationContext的典型用法代碼示例。如果您正苦於以下問題:Java JsonSerializationContext類的具體用法?Java JsonSerializationContext怎麽用?Java JsonSerializationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonSerializationContext類屬於com.google.gson包,在下文中一共展示了JsonSerializationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
protected void serialize(JsonObject json, JsonSerializationContext context)
{
    if (this.functions != null && this.functions.length > 0)
    {
        json.add("functions", context.serialize(this.functions));
    }

    ResourceLocation resourcelocation = (ResourceLocation)Item.REGISTRY.getNameForObject(this.item);

    if (resourcelocation == null)
    {
        throw new IllegalArgumentException("Can\'t serialize unknown item " + this.item);
    }
    else
    {
        json.addProperty("name", resourcelocation.toString());
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:19,代碼來源:LootEntryItem.java

示例2: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
@Override
public JsonElement serialize(final ProfilePropertyMap src, final Type typeOfSrc, final JsonSerializationContext context) {
  final JsonArray result = new JsonArray();

  for(final ProfileProperty property : src.values()) {
    final JsonObject object = new JsonObject();

    object.addProperty("name", property.name());
    object.addProperty("value", property.value());

    @Nullable final String signature = property.signature();
    if(signature != null) {
      object.addProperty("signature", signature);
    }

    result.add(object);
  }

  return result;
}
 
開發者ID:KyoriPowered,項目名稱:yggdrasil,代碼行數:21,代碼來源:ProfilePropertyMapSerializer.java

示例3: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
@Override
public JsonElement serialize(AttachmentsEntity attachmentsEntity, Type type, JsonSerializationContext context) {
    List<Entity> entities = attachmentsEntity.getEntities();

    JsonArray array = new JsonArray(entities.size());
    for(Entity entity : entities){
        int dbotype = AttachmentsTypes.typeForInstance(entity);

        JsonObject o = new JsonObject();
        o.add(KEY_ENTITY_TYPE, new JsonPrimitive(dbotype));
        o.add(KEY_ENTITY, context.serialize(entity));

        array.add(o);
    }

    return array;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:18,代碼來源:AttachmentsDboAdapter.java

示例4: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
public JsonElement serialize(ServerStatusResponse p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
    JsonObject jsonobject = new JsonObject();

    if (p_serialize_1_.getServerDescription() != null)
    {
        jsonobject.add("description", p_serialize_3_.serialize(p_serialize_1_.getServerDescription()));
    }

    if (p_serialize_1_.getPlayerCountData() != null)
    {
        jsonobject.add("players", p_serialize_3_.serialize(p_serialize_1_.getPlayerCountData()));
    }

    if (p_serialize_1_.getProtocolVersionInfo() != null)
    {
        jsonobject.add("version", p_serialize_3_.serialize(p_serialize_1_.getProtocolVersionInfo()));
    }

    if (p_serialize_1_.getFavicon() != null)
    {
        jsonobject.addProperty("favicon", p_serialize_1_.getFavicon());
    }

    return jsonobject;
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:27,代碼來源:ServerStatusResponse.java

示例5: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
public JsonElement serialize(ServerStatusResponse.PlayerCountData p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
    JsonObject jsonobject = new JsonObject();
    jsonobject.addProperty("max", (Number)Integer.valueOf(p_serialize_1_.getMaxPlayers()));
    jsonobject.addProperty("online", (Number)Integer.valueOf(p_serialize_1_.getOnlinePlayerCount()));

    if (p_serialize_1_.getPlayers() != null && p_serialize_1_.getPlayers().length > 0)
    {
        JsonArray jsonarray = new JsonArray();

        for (int i = 0; i < p_serialize_1_.getPlayers().length; ++i)
        {
            JsonObject jsonobject1 = new JsonObject();
            UUID uuid = p_serialize_1_.getPlayers()[i].getId();
            jsonobject1.addProperty("id", uuid == null ? "" : uuid.toString());
            jsonobject1.addProperty("name", p_serialize_1_.getPlayers()[i].getName());
            jsonarray.add(jsonobject1);
        }

        jsonobject.add("sample", jsonarray);
    }

    return jsonobject;
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:25,代碼來源:ServerStatusResponse.java

示例6: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
public void serialize(JsonObject object, EnchantRandomly functionClazz, JsonSerializationContext serializationContext)
{
    if (!functionClazz.enchantments.isEmpty())
    {
        JsonArray jsonarray = new JsonArray();

        for (Enchantment enchantment : functionClazz.enchantments)
        {
            ResourceLocation resourcelocation = (ResourceLocation)Enchantment.REGISTRY.getNameForObject(enchantment);

            if (resourcelocation == null)
            {
                throw new IllegalArgumentException("Don\'t know how to serialize enchantment " + enchantment);
            }

            jsonarray.add(new JsonPrimitive(resourcelocation.toString()));
        }

        object.add("enchantments", jsonarray);
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:22,代碼來源:EnchantRandomly.java

示例7: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
@Override
public JsonElement serialize(WxMpTemplateMessage message, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject messageJson = new JsonObject();
  messageJson.addProperty("touser", message.getToUser());
  messageJson.addProperty("template_id", message.getTemplateId());
  if (message.getUrl() != null) {
    messageJson.addProperty("url", message.getUrl());
  }

  JsonObject data = new JsonObject();
  messageJson.add("data", data);

  for (WxMpTemplateData datum : message.getData()) {
    JsonObject dataJson = new JsonObject();
    dataJson.addProperty("value", datum.getValue());
    if (datum.getColor() != null) {
      dataJson.addProperty("color", datum.getColor());
    }
    data.add(datum.getName(), dataJson);
  }

  return messageJson;
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:24,代碼來源:WxMpTemplateMessageGsonAdapter.java

示例8: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
public JsonElement serialize(LootPool p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
    JsonObject jsonobject = new JsonObject();
    jsonobject.add("entries", p_serialize_3_.serialize(p_serialize_1_.lootEntries));
    jsonobject.add("rolls", p_serialize_3_.serialize(p_serialize_1_.rolls));

    if (p_serialize_1_.bonusRolls.getMin() != 0.0F && p_serialize_1_.bonusRolls.getMax() != 0.0F)
    {
        jsonobject.add("bonus_rolls", p_serialize_3_.serialize(p_serialize_1_.bonusRolls));
    }

    if (!ArrayUtils.isEmpty((Object[])p_serialize_1_.poolConditions))
    {
        jsonobject.add("conditions", p_serialize_3_.serialize(p_serialize_1_.poolConditions));
    }

    return jsonobject;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:19,代碼來源:LootPool.java

示例9: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
public JsonElement serialize(PackMetadataSection p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
    JsonObject jsonobject = new JsonObject();
    jsonobject.addProperty("pack_format", (Number)Integer.valueOf(p_serialize_1_.getPackFormat()));
    jsonobject.add("description", p_serialize_3_.serialize(p_serialize_1_.getPackDescription()));
    return jsonobject;
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:8,代碼來源:PackMetadataSectionSerializer.java

示例10: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
@Override
public JsonElement serialize(NavigationMetadata src, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject metadata = new JsonObject();
  serializeRequired(src, metadata);
  serializeOptional(src, metadata);
  return metadata;
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:8,代碼來源:NavigationMetadataSerializer.java

示例11: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
public JsonElement serialize(AnimationMetadataSection p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
    JsonObject jsonobject = new JsonObject();
    jsonobject.addProperty("frametime", (Number)Integer.valueOf(p_serialize_1_.getFrameTime()));

    if (p_serialize_1_.getFrameWidth() != -1)
    {
        jsonobject.addProperty("width", (Number)Integer.valueOf(p_serialize_1_.getFrameWidth()));
    }

    if (p_serialize_1_.getFrameHeight() != -1)
    {
        jsonobject.addProperty("height", (Number)Integer.valueOf(p_serialize_1_.getFrameHeight()));
    }

    if (p_serialize_1_.getFrameCount() > 0)
    {
        JsonArray jsonarray = new JsonArray();

        for (int i = 0; i < p_serialize_1_.getFrameCount(); ++i)
        {
            if (p_serialize_1_.frameHasTime(i))
            {
                JsonObject jsonobject1 = new JsonObject();
                jsonobject1.addProperty("index", (Number)Integer.valueOf(p_serialize_1_.getFrameIndex(i)));
                jsonobject1.addProperty("time", (Number)Integer.valueOf(p_serialize_1_.getFrameTimeSingle(i)));
                jsonarray.add(jsonobject1);
            }
            else
            {
                jsonarray.add(new JsonPrimitive(Integer.valueOf(p_serialize_1_.getFrameIndex(i))));
            }
        }

        jsonobject.add("frames", jsonarray);
    }

    return jsonobject;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:40,代碼來源:AnimationMetadataSectionSerializer.java

示例12: serializeNewData

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
private void serializeNewData(NavigationRerouteData src, JsonSerializationContext context,
                              JsonObject rerouteData) {
  JsonObject newData = context.serialize(src.getNavigationNewData()).getAsJsonObject();
  for (Map.Entry<String, JsonElement> e : newData.entrySet()) {
    rerouteData.add(e.getKey(), e.getValue());
  }
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:8,代碼來源:RerouteDataSerializer.java

示例13: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
@Override
public JsonElement serialize(final Component component, final Type type, final JsonSerializationContext context) {
  final JsonObject object = new JsonObject();
  if(component instanceof TextComponent) {
    object.addProperty("text", ((TextComponent) component).content());
  } else if(component instanceof TranslatableComponent) {
    final TranslatableComponent tc = (TranslatableComponent) component;
    object.addProperty("translate", tc.key());
    if(!tc.args().isEmpty()) {
      final JsonArray with = new JsonArray();
      for(final Component arg : tc.args()) {
        with.add(this.serialize(arg, arg.getClass(), context));
      }
      object.add("with", with);
    }
  } else if(component instanceof ScoreComponent) {
    final ScoreComponent sc = (ScoreComponent) component;
    final JsonObject score = new JsonObject();
    score.addProperty("name", sc.name());
    score.addProperty("objective", sc.objective());
    // score component value is optional
    if(sc.value() != null) score.addProperty("value", sc.value());
    object.add("score", score);
  } else if(component instanceof SelectorComponent) {
    object.addProperty("selector", ((SelectorComponent) component).pattern());
  } else if(component instanceof KeybindComponent) {
    object.addProperty("keybind", ((KeybindComponent) component).keybind());
  } else {
    throw new IllegalArgumentException("Don't know how to serialize " + component + " as a Component");
  }

  if(!component.children().isEmpty()) {
    final JsonArray extra = new JsonArray();
    for(final Component child : component.children()) {
      extra.add(this.serialize(child, child.getClass(), context));
    }
    object.add("extra", extra);
  }

  if(component.hasStyling()) {
    for(final TextDecoration decoration : TextDecoration.values()) {
      final TextDecoration.State flag = component.decoration(decoration);
      if(flag != TextDecoration.State.NOT_SET) object.addProperty(decoration.toString(), flag == TextDecoration.State.TRUE);
    }
    if(component.color() != null) object.add("color", context.serialize(component.color()));
    if(component.insertion() != null) object.add("insertion", context.serialize(component.insertion()));
    @Nullable final ClickEvent clickEvent = component.clickEvent();
    if(clickEvent != null) {
      final JsonObject clickEventO = new JsonObject();
      clickEventO.add("action", context.serialize(clickEvent.action()));
      clickEventO.addProperty("value", clickEvent.value());
      object.add("clickEvent", clickEventO);
    }
    @Nullable final HoverEvent hoverEvent = component.hoverEvent();
    if(hoverEvent != null) {
      final JsonObject hoverEventO = new JsonObject();
      hoverEventO.add("action", context.serialize(hoverEvent.action()));
      hoverEventO.add("value", this.serialize(hoverEvent.value(), type, context));
      object.add("hoverEvent", hoverEventO);
    }
  }

  return object;
}
 
開發者ID:KyoriPowered,項目名稱:text,代碼行數:65,代碼來源:GsonComponentSerializer.java

示例14: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
@Override
public JsonElement serialize(final RemoteCookbook cookBook, final Type type, final JsonSerializationContext context) {

    Preconditions.checkNotNull(cookBook);
    Preconditions.checkNotNull(type);
    Preconditions.checkNotNull(context);

    final JsonObject jsonObject = new JsonObject();

    jsonObject.add("name", context.serialize(cookBook.name));
    jsonObject.add("url", context.serialize(cookBook.url));

    return jsonObject;
}
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:15,代碼來源:RemoteCookBookSerializer.java

示例15: serialize

import com.google.gson.JsonSerializationContext; //導入依賴的package包/類
@Override
public JsonElement serialize(NavigationLocationData src, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject locationData = new JsonObject();
  JsonArray locationsBefore = context.serialize(src.getLocationsBefore()).getAsJsonArray();
  JsonArray locationsAfter = context.serialize(src.getLocationsAfter()).getAsJsonArray();
  locationData.add(LOCATIONS_BEFORE, locationsBefore);
  locationData.add(LOCATIONS_AFTER, locationsAfter);
  return locationData;
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:10,代碼來源:LocationDataSerializer.java


注:本文中的com.google.gson.JsonSerializationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。