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


Java JsonDeserializationContext.deserialize方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:ZafraniTechLLC,項目名稱:Companion-For-PUBG-Android,代碼行數:21,代碼來源:Weapon.java

示例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);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:24,代碼來源:FeedbackDtoAdapter.java

示例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);
}
 
開發者ID:hhu-bsinfo,項目名稱:dxram,代碼行數:25,代碼來源:ApplicationGsonContext.java

示例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);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:19,代碼來源:DboWrapperAdapter.java

示例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;
}
 
開發者ID:ObsidianSuite,項目名稱:ObsidianSuite,代碼行數:20,代碼來源:JsonModel.java

示例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);
}
 
開發者ID:hhu-bsinfo,項目名稱:dxram,代碼行數:27,代碼來源:DXRAMGsonContext.java

示例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);
		}
	}
}
 
開發者ID:LogicalOverflow,項目名稱:java-champion-gg-wrapper,代碼行數:13,代碼來源:ErrorResponseDeserializer.java

示例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);
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:16,代碼來源:PackMetadataSectionSerializer.java

示例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);
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:32,代碼來源:ModelBlock.java

示例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;
}
 
開發者ID:dfrommi,項目名稱:openhab-tado,代碼行數:15,代碼來源:ZoneCapabilitiesConverter.java

示例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);
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:12,代碼來源:JsonUtils.java

示例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);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:10,代碼來源:BlockPartFace.java

示例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"));
}
 
開發者ID:FelixGail,項目名稱:gplaymusic,代碼行數:14,代碼來源:ListenNowItemDeserializer.java

示例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;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:28,代碼來源:SearchDialogsResponseAdapter.java

示例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;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:36,代碼來源:AttachmentsDtoAdapter.java


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