本文整理汇总了Java中com.google.gson.JsonDeserializationContext.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Java JsonDeserializationContext.deserialize方法的具体用法?Java JsonDeserializationContext.deserialize怎么用?Java JsonDeserializationContext.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonDeserializationContext
的用法示例。
在下文中一共展示了JsonDeserializationContext.deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public Weapon deserialize(final JsonElement json,
final java.lang.reflect.Type typeOfT,
final JsonDeserializationContext context) throws JsonParseException {
if (json == null) {
return null;
}
final JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject == null) {
return null;
}
String type = jsonObject.get(TYPE).getAsString();
if (Melee.name().equalsIgnoreCase(type)) {
return context.deserialize(jsonObject, MeleeWeapon.class);
} else if (Grenade.name().equalsIgnoreCase(type)) {
return context.deserialize(jsonObject, GrenadeWeapon.class);
} else {
return context.deserialize(jsonObject, ProjectileWeapon.class);
}
}
示例2: parse
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
void parse(JsonObject root, T dto, JsonDeserializationContext context) {
super.parse(root, dto, context);
dto.copies = context.deserialize(root.get("feedback"), Copies.class);
Class<? extends Copyable> copyClass;
switch (dto.type) {
case "copy_post":
copyClass = VKApiPost.class;
break;
case "copy_photo":
copyClass = VKApiPhoto.class;
break;
case "copy_video":
copyClass = VKApiVideo.class;
break;
default:
throw new UnsupportedOperationException("Unsupported feedback type: " + dto.type);
}
dto.what = context.deserialize(root.get("parent"), copyClass);
}
示例3: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public AbstractApplication deserialize(final JsonElement p_jsonElement, final Type p_type,
final JsonDeserializationContext p_jsonDeserializationContext) {
JsonObject jsonObj = p_jsonElement.getAsJsonObject();
String className = jsonObj.get("m_class").getAsString();
boolean enabled = jsonObj.get("m_enabled").getAsBoolean();
// don't create instance if disabled
if (!enabled) {
return null;
}
if (!m_appClass.getSuperclass().equals(AbstractApplication.class)) {
// check if there is an "interface"/abstract class between DXRAMComponent and the instance to
// create
if (!m_appClass.getSuperclass().getSuperclass().equals(AbstractApplication.class)) {
LOGGER.fatal("Could class '%s' is not a subclass of AbstractApplication, check your config file", className);
return null;
}
}
return p_jsonDeserializationContext.deserialize(p_jsonElement, m_appClass);
}
示例4: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public EntityWrapper deserialize(JsonElement jsonElement, Type typef, JsonDeserializationContext context) throws JsonParseException {
if (jsonElement == null || jsonElement instanceof JsonNull) {
return null;
}
JsonObject root = jsonElement.getAsJsonObject();
boolean isNull = root.get(KEY_IS_NULL).getAsBoolean();
Entity entity = null;
if (!isNull) {
int dbotype = root.get(KEY_TYPE).getAsInt();
entity = context.deserialize(root.get(KEY_ENTITY), AttachmentsTypes.classForType(dbotype));
}
return new EntityWrapper(entity);
}
示例5: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public JsonJsonModel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException
{
JsonObject jsonObject = json.getAsJsonObject();
JsonJsonModel model = JsonFactory.getGson().fromJson(json, JsonJsonModel.class);
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet())
{
if (entry.getKey().equals("textures"))
{
Map<String, String> map = context.deserialize(entry.getValue(), Map.class);
for (String o : map.keySet())
{
model.texMap.put(o, map.get(o));
}
}
}
return model;
}
示例6: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public AbstractDXRAMComponentConfig deserialize(final JsonElement p_jsonElement, final Type p_type,
final JsonDeserializationContext p_jsonDeserializationContext) {
JsonObject jsonObj = p_jsonElement.getAsJsonObject();
String className = jsonObj.get("m_class").getAsString();
Class<?> clazz;
try {
clazz = Class.forName(className);
} catch (final ClassNotFoundException ignore) {
LOGGER.fatal("Could not find component config for class name '%s', check your config file", className);
return null;
}
if (!clazz.getSuperclass().equals(AbstractDXRAMComponentConfig.class)) {
// check if there is an "interface"/abstract class between DXRAMComponent and the instance to
// create
if (!clazz.getSuperclass().getSuperclass().equals(AbstractDXRAMComponentConfig.class)) {
LOGGER.fatal("Class '%s' is not a subclass of AbstractDXRAMComponentConfig, check your config file", className);
return null;
}
}
return p_jsonDeserializationContext.deserialize(p_jsonElement, clazz);
}
示例7: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public ErrorResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
return context.deserialize(json, NormalErrorResponse.class);
} catch (JsonParseException normal) {
try {
return context.deserialize(json, AdvancedErrorResponse.class);
} catch (JsonParseException advanced) {
throw new BothAttemptsFailedException(normal, advanced);
}
}
}
示例8: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
public PackMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
IChatComponent ichatcomponent = (IChatComponent)p_deserialize_3_.deserialize(jsonobject.get("description"), IChatComponent.class);
if (ichatcomponent == null)
{
throw new JsonParseException("Invalid/missing description!");
}
else
{
int i = JsonUtils.getInt(jsonobject, "pack_format");
return new PackMetadataSection(ichatcomponent, i);
}
}
示例9: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
public ModelBlock deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
List<BlockPart> list = this.getModelElements(p_deserialize_3_, jsonobject);
String s = this.getParent(jsonobject);
boolean flag = StringUtils.isEmpty(s);
boolean flag1 = list.isEmpty();
if (flag1 && flag)
{
throw new JsonParseException("BlockModel requires either elements or parent, found neither");
}
else if (!flag && !flag1)
{
throw new JsonParseException("BlockModel requires either elements or parent, found both");
}
else
{
Map<String, String> map = this.getTextures(jsonobject);
boolean flag2 = this.getAmbientOcclusionEnabled(jsonobject);
ItemCameraTransforms itemcameratransforms = ItemCameraTransforms.DEFAULT;
if (jsonobject.has("display"))
{
JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonobject, "display");
itemcameratransforms = (ItemCameraTransforms)p_deserialize_3_.deserialize(jsonobject1, ItemCameraTransforms.class);
}
return flag1 ? new ModelBlock(new ResourceLocation(s), map, flag2, true, itemcameratransforms) : new ModelBlock(list, map, flag2, true, itemcameratransforms);
}
}
示例10: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public GenericZoneCapabilities deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
TadoSystemType settingType = TadoSystemType.valueOf(json.getAsJsonObject().get("type").getAsString());
if (settingType == TadoSystemType.HEATING) {
return context.deserialize(json, HeatingCapabilities.class);
} else if (settingType == TadoSystemType.AIR_CONDITIONING) {
return context.deserialize(json, AirConditioningCapabilities.class);
} else if (settingType == TadoSystemType.HOT_WATER) {
return context.deserialize(json, HotWaterCapabilities.class);
}
return null;
}
示例11: deserializeClass
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
public static <T> T deserializeClass(@Nullable JsonElement json, String memberName, JsonDeserializationContext context, Class <? extends T > adapter)
{
if (json != null)
{
return context.deserialize(json, adapter);
}
else
{
throw new JsonSyntaxException("Missing " + memberName);
}
}
示例12: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
public BlockPartFace deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
EnumFacing enumfacing = this.parseCullFace(jsonobject);
int i = this.parseTintIndex(jsonobject);
String s = this.parseTexture(jsonobject);
BlockFaceUV blockfaceuv = (BlockFaceUV)p_deserialize_3_.deserialize(jsonobject, BlockFaceUV.class);
return new BlockPartFace(enumfacing, i, s, blockfaceuv);
}
示例13: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public ListenNowItem deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException {
JsonObject content = je.getAsJsonObject();
if (content.has("album")) {
addSubEntries(content, content.getAsJsonObject("album"));
return jdc.deserialize(content, ListenNowAlbum.class);
}
if (content.has("radio_station")) {
addSubEntries(content, content.getAsJsonObject("radio_station"));
return jdc.deserialize(content, ListenNowStation.class);
}
throw new JsonParseException(Language.get("listenNowItem.UnknownType"));
}
示例14: deserialize
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
@Override
public SearchDialogsResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonArray array = json.getAsJsonArray();
SearchDialogsResponse response = new SearchDialogsResponse();
List<SearchDialogsResponse.AbsChattable> list = new ArrayList<>(array.size());
for(int i = 0; i < array.size(); i++){
JsonObject object = array.get(i).getAsJsonObject();
String type = object.get("type").getAsString();
if("profile".equals(type)){
VKApiUser user = context.deserialize(object, VKApiUser.class);
list.add(new SearchDialogsResponse.User(user));
} else if("group".equals(type) || "page".equals(type) || "event".equals(type)){
VKApiCommunity community = context.deserialize(object, VKApiCommunity.class);
list.add(new SearchDialogsResponse.Community(community));
} else if("chat".equals(type)){
VKApiChat chat = context.deserialize(object, VKApiChat.class);
list.add(new SearchDialogsResponse.Chat(chat));
}
}
response.setData(list);
return response;
}
示例15: parse
import com.google.gson.JsonDeserializationContext; //导入方法依赖的package包/类
private VKApiAttachment parse(String type, JsonObject root, JsonDeserializationContext context){
JsonElement o = root.get(type);
//{"type":"photos_list","photos_list":["406536042_456239026"]}
if (VkApiAttachments.TYPE_PHOTO.equals(type)) {
return context.deserialize(o, VKApiPhoto.class);
} else if (VkApiAttachments.TYPE_VIDEO.equals(type)) {
return context.deserialize(o, VKApiVideo.class);
} else if (VkApiAttachments.TYPE_AUDIO.equals(type)) {
return context.deserialize(o, VKApiAudio.class);
} else if (VkApiAttachments.TYPE_DOC.equals(type)) {
return context.deserialize(o, VkApiDoc.class);
} else if (VkApiAttachments.TYPE_POST.equals(type)) {
return context.deserialize(o, VKApiPost.class);
//} else if (VkApiAttachments.TYPE_POSTED_PHOTO.equals(type)) {
// return context.deserialize(o, VKApiPostedPhoto.class);
} else if (VkApiAttachments.TYPE_LINK.equals(type)) {
return context.deserialize(o, VKApiLink.class);
//} else if (VkApiAttachments.TYPE_NOTE.equals(type)) {
// return context.deserialize(o, VKApiNote.class);
//} else if (VkApiAttachments.TYPE_APP.equals(type)) {
// return context.deserialize(o, VKApiApplicationContent.class);
} else if (VkApiAttachments.TYPE_POLL.equals(type)) {
return context.deserialize(o, VKApiPoll.class);
} else if (VkApiAttachments.TYPE_WIKI_PAGE.equals(type)) {
return context.deserialize(o, VKApiWikiPage.class);
//} else if (VkApiAttachments.TYPE_ALBUM.equals(type)) {
// return context.deserialize(o, VKApiPhotoAlbum.class); // not supported yet
} else if (VkApiAttachments.TYPE_STICKER.equals(type)) {
return context.deserialize(o, VKApiSticker.class);
}
return null;
}