当前位置: 首页>>代码示例>>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;未经允许,请勿转载。