本文整理汇总了Java中com.google.gson.JsonSerializationContext.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java JsonSerializationContext.serialize方法的具体用法?Java JsonSerializationContext.serialize怎么用?Java JsonSerializationContext.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonSerializationContext
的用法示例。
在下文中一共展示了JsonSerializationContext.serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(Holder src, Type type, JsonSerializationContext context) {
JsonObject root = new JsonObject();
JsonElement value = context.serialize(src.value());
root.addProperty("id", src.id());
if (value.isJsonObject()) {
value.getAsJsonObject().addProperty(Holder.TYPE_PROPERTY, src.value().getClass().getName());
}
root.add(VALUE_PROPERTY, value);
return root;
}
示例2: serializeChatStyle
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
private void serializeChatStyle(Style style, JsonObject object, JsonSerializationContext ctx)
{
JsonElement jsonelement = ctx.serialize(style);
if (jsonelement.isJsonObject())
{
JsonObject jsonobject = (JsonObject)jsonelement;
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
object.add((String)entry.getKey(), (JsonElement)entry.getValue());
}
}
}
示例3: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(final AbstractDXRAMServiceConfig p_abstractDXRAMService, final Type p_type,
final JsonSerializationContext p_jsonSerializationContext) {
Class<?> clazz;
try {
clazz = Class.forName(p_abstractDXRAMService.getClass().getName());
} catch (final ClassNotFoundException ignore) {
return null;
}
return p_jsonSerializationContext.serialize(p_abstractDXRAMService, clazz);
}
示例4: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(PlayerCharacter src, Type typeOfSrc, JsonSerializationContext context) {
BaseClass characterClass = src.getCharClass();
characterClass.setCharacter(null);
Type equipListType = new TypeToken<ArrayList<Equipment>>() {
}.getType();
Type moneyMapType = new TypeToken<HashMap<Money, Integer>>() {
}.getType();
JsonObject rootObject = new JsonObject();
rootObject.add("mScores", context.serialize(src.getScores()));
rootObject.add("mCharClass", context.serialize(src.getCharClass(), BaseClass.class));
rootObject.add("mGender", context.serialize(src.getGender()));
rootObject.add("mMoney", context.serialize(src.getMoney(), moneyMapType));
rootObject.add("mAge", context.serialize(src.getAge()));
rootObject.add("mName", context.serialize(src.getName()));
System.out.println(getGson().toJsonTree(src.getInventory(), equipListType));
rootObject.add("mInventory", getGson().toJsonTree(src.getInventory(), equipListType));
rootObject.add("mCurrentWeapon", context.serialize(src.getCurrentWeapon()));
rootObject.add("mHelmet", context.serialize(src.getHelmet()));
rootObject.add("mBreastplate", context.serialize(src.getBreastplate()));
rootObject.add("mShield", context.serialize(src.getShield()));
rootObject.add("mPatron", context.serialize(src.getPatron()));
JsonElement classJson = context.serialize(characterClass);
rootObject.add("mCharClass", classJson);
characterClass.setCharacter(src);
return rootObject;
}
示例5: serializeChatStyle
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
private void serializeChatStyle(ChatStyle style, JsonObject object, JsonSerializationContext ctx)
{
JsonElement jsonelement = ctx.serialize(style);
if (jsonelement.isJsonObject())
{
JsonObject jsonobject = (JsonObject)jsonelement;
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
object.add((String)entry.getKey(), (JsonElement)entry.getValue());
}
}
}
示例6: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(GenericZoneSetting src, Type srcType, JsonSerializationContext context) {
if (src instanceof HeatingZoneSetting) {
return context.serialize(src, HeatingZoneSetting.class);
} else if (src instanceof CoolingZoneSetting) {
return context.serialize(src, CoolingZoneSetting.class);
} else if (src instanceof HotWaterZoneSetting) {
return context.serialize(src, HotWaterZoneSetting.class);
}
return new JsonObject();
}
示例7: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(OverlayTerminationCondition src, Type srcType, JsonSerializationContext context) {
if (src instanceof ManualTerminationCondition) {
return context.serialize(src, ManualTerminationCondition.class);
} else if (src instanceof TadoModeTerminationCondition) {
return context.serialize(src, TadoModeTerminationCondition.class);
} else if (src instanceof TimerTerminationCondition) {
return context.serialize(src, TimerTerminationCondition.class);
}
return new JsonObject();
}
示例8: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(GenericZoneCapabilities src, Type srcType, JsonSerializationContext context) {
if (src instanceof HeatingCapabilities) {
return context.serialize(src, HeatingCapabilities.class);
} else if (src instanceof AirConditioningCapabilities) {
return context.serialize(src, AirConditioningCapabilities.class);
} else if (src instanceof HotWaterCapabilities) {
return context.serialize(src, HotWaterCapabilities.class);
}
return new JsonObject();
}
示例9: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(PlayerCharacter src, Type typeOfSrc, JsonSerializationContext context) {
BaseClass characterClass = src.getCharClass();
characterClass.setCharacter(null);
Type equipListType = new TypeToken<ArrayList<Equipment>>() {
}.getType();
Type moneyMapType = new TypeToken<HashMap<Money, Integer>>() {
}.getType();
JsonObject rootObject = new JsonObject();
rootObject.add("mScores", context.serialize(src.getScores()));
rootObject.add("mCharClass", context.serialize(src.getCharClass(), BaseClass.class));
rootObject.add("mGender", context.serialize(src.getGender()));
rootObject.add("mMoney", context.serialize(src.getMoney(), moneyMapType));
rootObject.add("mAge", context.serialize(src.getAge()));
rootObject.add("mName", context.serialize(src.getName()));
System.out.println(getGson().toJsonTree(src.getInventory(), equipListType));
rootObject.add("mInventory", getGson().toJsonTree(src.getInventory(), equipListType));
rootObject.add("mCurrentWeapon", context.serialize(src.getCurrentWeapon()));
rootObject.add("mHelmet", context.serialize(src.getHelmet()));
rootObject.add("mBreastplate", context.serialize(src.getBreastplate()));
rootObject.add("mShield", context.serialize(src.getShield()));
rootObject.add("mPatron", context.serialize(src.getPatron()));
JsonElement classJson = context.serialize(characterClass);
classJson.getAsJsonObject().remove("mResId");
rootObject.add("mCharClass", classJson);
characterClass.setCharacter(src);
return rootObject;
}
示例10: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
@Nonnull
public JsonElement serialize(@Nonnull Phase src, @Nonnull Type typeOfSrc, @Nonnull JsonSerializationContext context) {
return context.serialize(src, src.getClass());
}
示例11: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(final AbstractApplication p_abstractApplication, final Type p_type,
final JsonSerializationContext p_jsonSerializationContext) {
return p_jsonSerializationContext.serialize(p_abstractApplication, m_appClass);
}
示例12: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(CredentialDetail src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src, src.getClass());
}
示例13: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(AbstractButton button, Type type, JsonSerializationContext context) {
return context.serialize(button);
}
示例14: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(Button button, Type type, JsonSerializationContext context) {
return context.serialize(button);
}
示例15: serialize
import com.google.gson.JsonSerializationContext; //导入方法依赖的package包/类
@Override
public JsonElement serialize(AbstractMenu menu, Type type, JsonSerializationContext context) {
return context.serialize(menu);
}