本文整理汇总了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());
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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;
}
示例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;
}