当前位置: 首页>>代码示例>>Java>>正文


Java JsonDeserializationContext类代码示例

本文整理汇总了Java中com.google.gson.JsonDeserializationContext的典型用法代码示例。如果您正苦于以下问题:Java JsonDeserializationContext类的具体用法?Java JsonDeserializationContext怎么用?Java JsonDeserializationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonDeserializationContext类属于com.google.gson包,在下文中一共展示了JsonDeserializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
@Nullable
public Feature deserialize(@Nonnull JsonElement json, @Nonnull Type typeOfT, @Nonnull JsonDeserializationContext context)
        throws JsonParseException {
    try {
        JsonObject jsonObject = json.getAsJsonObject();

        // default path
        String name = jsonObject.get("name").getAsString();
        if (!name.contains(".")) {
            name = DEFAULT_PATH + "." + name;
        }

        Class clazz = Class.forName(name);
        Feature feature = context.deserialize(json, clazz);
        injector.injectMembers(feature);
        return feature;
    } catch (Exception e) {
        log.log(Level.WARNING, "Could not deserialize feature:\n" + json.toString(), e);
    }
    return null;
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:23,代码来源:FeatureTypeAdapter.java

示例2: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
public SetAttributes deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
    JsonArray jsonarray = JsonUtils.getJsonArray(object, "modifiers");
    SetAttributes.Modifier[] asetattributes$modifier = new SetAttributes.Modifier[jsonarray.size()];
    int i = 0;

    for (JsonElement jsonelement : jsonarray)
    {
        asetattributes$modifier[i++] = SetAttributes.Modifier.deserialize(JsonUtils.getJsonObject(jsonelement, "modifier"), deserializationContext);
    }

    if (asetattributes$modifier.length == 0)
    {
        throw new JsonSyntaxException("Invalid attribute modifiers array; cannot be empty");
    }
    else
    {
        return new SetAttributes(conditionsIn, asetattributes$modifier);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:21,代码来源:SetAttributes.java

示例3: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
public VariantList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    List<Variant> list = Lists.<Variant>newArrayList();

    if (p_deserialize_1_.isJsonArray())
    {
        JsonArray jsonarray = p_deserialize_1_.getAsJsonArray();

        if (jsonarray.size() == 0)
        {
            throw new JsonParseException("Empty variant array");
        }

        for (JsonElement jsonelement : jsonarray)
        {
            list.add((Variant)p_deserialize_3_.deserialize(jsonelement, Variant.class));
        }
    }
    else
    {
        list.add((Variant)p_deserialize_3_.deserialize(p_deserialize_1_, Variant.class));
    }

    return new VariantList(list);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:26,代码来源:VariantList.java

示例4: parseMapVariants

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
protected Map<String, VariantList> parseMapVariants(JsonDeserializationContext deserializationContext, JsonObject object)
{
    Map<String, VariantList> map = Maps.<String, VariantList>newHashMap();

    if (object.has("variants"))
    {
        JsonObject jsonobject = JsonUtils.getJsonObject(object, "variants");

        for (Entry<String, JsonElement> entry : jsonobject.entrySet())
        {
            map.put(entry.getKey(), (VariantList)deserializationContext.deserialize((JsonElement)entry.getValue(), VariantList.class));
        }
    }

    return map;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:17,代码来源:ModelBlockDefinition.java

示例5: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public VKApiComment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject root = json.getAsJsonObject();
    VKApiComment dto = new VKApiComment();

    dto.id = optInt(root, "id");
    dto.from_id = optInt(root, "from_id");

    if(dto.from_id == 0){
        dto.from_id = optInt(root, "owner_id");
    }

    dto.date = optLong(root, "date");
    dto.text = optString(root, "text");
    dto.reply_to_user = optInt(root, "reply_to_user");
    dto.reply_to_comment = optInt(root, "reply_to_comment");

    if(root.has("attachments")){
        dto.attachments = context.deserialize(root.get("attachments"), VkApiAttachments.class);
    }

    if(root.has("likes")){
        JsonObject likesRoot = root.getAsJsonObject("likes");
        dto.likes = optInt(likesRoot, "count");
        dto.user_likes = optIntAsBoolean(likesRoot, "user_likes");
        dto.can_like = optIntAsBoolean(likesRoot, "can_like");
    }

    dto.can_edit = optIntAsBoolean(root, "can_edit");
    return dto;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:32,代码来源:CommentDtoAdapter.java

示例6: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public VideoList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    VideoList videoList = new VideoList();

    JsonObject jsonObject = json.getAsJsonObject().getAsJsonObject("data");
    videoList.setAfter(jsonObject.getAsJsonPrimitive("after").getAsString());

    Iterator<JsonElement> videoListJsonIterator = jsonObject.getAsJsonArray("children").iterator();
    while (videoListJsonIterator.hasNext()) {
        JsonElement videoItemJson = videoListJsonIterator.next();
        try {
            Video video = context.deserialize(videoItemJson, Video.class);
            if (video != null) {
                videoList.addVideo(video);
            }
        } catch (Throwable t) {
            Log.e(TAG, "Failed to deserialize a video item : " + videoItemJson, t);
        }
    }

    return videoList;
}
 
开发者ID:aprochukhan,项目名称:Android-MVVM-Example,代码行数:25,代码来源:VideoListDeserializer.java

示例7: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public Video deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    Video video = null;

    JsonObject jsonObject = json.getAsJsonObject().getAsJsonObject("data");
    String domain = jsonObject.getAsJsonPrimitive("domain").getAsString();

    if (isYoutubeDomain(domain)) {
        String url = jsonObject.getAsJsonPrimitive("url").getAsString();
        String youtubeId = getYoutubeId(url);
        if (youtubeId != null && youtubeId.length() > 0) {
            video = new Video(
                    jsonObject.getAsJsonPrimitive("id").getAsString(),
                    youtubeId,
                    jsonObject.getAsJsonPrimitive("created").getAsLong(),
                    jsonObject.getAsJsonPrimitive("title").getAsString(),
                    url
            );
        }
    }

    return video;
}
 
开发者ID:aprochukhan,项目名称:Android-MVVM-Example,代码行数:26,代码来源:VideoDeserializer.java

示例8: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public UserArray deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject root = json.getAsJsonObject();
    UserArray dto = new UserArray();

    dto.count = optInt(root, "count");

    if(root.has("items")){
        JsonArray array = root.getAsJsonArray("items");
        dto.ids = new int[array.size()];

        for(int i = 0; i < array.size(); i++){
            dto.ids[i] = array.get(i).getAsJsonObject().get("from_id").getAsInt();
        }
    } else {
        dto.ids = new int[0];
    }

    return dto;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:21,代码来源:FeedbackUserArrayDtoAdapter.java

示例9: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public URL deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {

    Preconditions.checkNotNull(jsonElement);
    Preconditions.checkNotNull(type);
    Preconditions.checkNotNull(context);

    if (jsonElement.getAsString() == null) {
        throw new JsonParseException("URL must be a string");
    }

    try {
        return new URL(jsonElement.getAsString());
    } catch (final MalformedURLException e) {
        throw new JsonParseException(e);
    }
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:18,代码来源:UrlDeserializer.java

示例10: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public FeatureCollectionDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {

	FeatureCollectionDto dto = new FeatureCollectionDto();
	List<FeatureDto> features = new ArrayList<>();
	dto.setFeatures(features);

	JsonObject asJsonObject = json.getAsJsonObject();
	JsonArray jsonArray = asJsonObject.get("features").getAsJsonArray();
	if (jsonArray == null) {
		return dto;
	}

	for (int i = 0; i < jsonArray.size(); i++) {
		JsonObject featureElement = jsonArray.get(i).getAsJsonObject();
		FeatureDto geometryDto = context.deserialize(featureElement, FeatureDto.class);
		features.add(geometryDto);
	}

	dto.setBbox(BoundingBoxParser.parseBbox(asJsonObject, context));

	return dto;
}
 
开发者ID:mokszr,项目名称:ultimate-geojson,代码行数:24,代码来源:FeatureCollectionDeserializer.java

示例11: parseVariants

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
protected ModelBlockDefinition.Variants parseVariants(JsonDeserializationContext p_178335_1_, Entry<String, JsonElement> p_178335_2_)
{
    String s = (String)p_178335_2_.getKey();
    List<ModelBlockDefinition.Variant> list = Lists.<ModelBlockDefinition.Variant>newArrayList();
    JsonElement jsonelement = (JsonElement)p_178335_2_.getValue();

    if (jsonelement.isJsonArray())
    {
        for (JsonElement jsonelement1 : jsonelement.getAsJsonArray())
        {
            list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement1, ModelBlockDefinition.Variant.class));
        }
    }
    else
    {
        list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement, ModelBlockDefinition.Variant.class));
    }

    return new ModelBlockDefinition.Variants(s, list);
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:21,代码来源:ModelBlockDefinition.java

示例12: 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

示例13: 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

示例14: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public AttachmentsEntity deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
    JsonArray array = jsonElement.getAsJsonArray();

    if(array.size() == 0){
        return new AttachmentsEntity(Collections.emptyList());
    }

    List<Entity> entities = new ArrayList<>(array.size());

    for(int i = 0; i < array.size(); i++){
        JsonObject o = array.get(i).getAsJsonObject();
        int dbotype = o.get(KEY_ENTITY_TYPE).getAsInt();
        entities.add(context.deserialize(o.get(KEY_ENTITY), AttachmentsTypes.classForType(dbotype)));
    }

    return new AttachmentsEntity(entities);
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:19,代码来源:AttachmentsDboAdapter.java

示例15: deserialize

import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public FieldMap deserialize(JsonElement json,
                            Type typeOfT,
                            JsonDeserializationContext context) throws JsonParseException {
    JsonObject rootObject = json.getAsJsonObject();

    Set<Map.Entry<String, JsonElement>> entrySet = rootObject.entrySet();

    FieldMap fieldMap = new FieldMap();
    for (Map.Entry<String, JsonElement> entry : entrySet) {
        JsonObject propertyObject = entry.getValue().getAsJsonObject();
        String propertyName = entry.getKey();

        parsePropertyObject(propertyObject, propertyName, fieldMap, context);
    }

    return fieldMap;
}
 
开发者ID:NomenSvyat,项目名称:SwitchBoxPlugin,代码行数:19,代码来源:FieldMapDeserializer.java


注:本文中的com.google.gson.JsonDeserializationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。