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


Java JsonParseException类代码示例

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


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

示例1: deserialize

import com.google.gson.JsonParseException; //导入依赖的package包/类
@Override
public Date deserialize(JsonElement element, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    String date = element.getAsString();

    @SuppressLint("SimpleDateFormat")
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    try {
        return formatter.parse(date);
    } catch (ParseException e) {
        Log.e(TAG, "Date parsing failed");
        Log.exception(e);
        return new Date();
    }
}
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:18,代码来源:DateDeserializer.java

示例2: isValidJSON

import com.google.gson.JsonParseException; //导入依赖的package包/类
private static boolean isValidJSON(String input) {
    if (StringUtils.isBlank(input)) {
        logger.warn("Parsing empty json string to protobuf is deprecated and will be removed in " +
                "the next major release");
        return false;
    }

    if (!input.startsWith("{")) {
        logger.warn("Parsing json string that does not start with { is deprecated and will be " +
                "removed in the next major release");
        return false;
    }

    try {
        new JsonParser().parse(input);
    } catch (JsonParseException ex) {
        return false;
    }

    return true;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:22,代码来源:ProtobufUtil.java

示例3: read

import com.google.gson.JsonParseException; //导入依赖的package包/类
@Override
public Date read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }

    if (in.peek() != JsonToken.STRING) {
        throw new JsonParseException("The date should be a string value");
    }

    Date date = deserializeToDate(in.nextString());

    if (dateType == Date.class) {
        return date;
    } else if (dateType == Timestamp.class) {
        return new Timestamp(date.getTime());
    } else if (dateType == java.sql.Date.class) {
        return new java.sql.Date(date.getTime());
    } else {
        // This must never happen: dateType is guarded in the primary constructor
        throw new AssertionError();
    }
}
 
开发者ID:CoryCharlton,项目名称:BittrexApi,代码行数:25,代码来源:DefaultDateTypeAdapter.java

示例4: parse

import com.google.gson.JsonParseException; //导入依赖的package包/类
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonSyntaxException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:Streams.java

示例5: deserialize

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

    dto.entries = new ArrayList<>(array.size());
    for(int i = 0; i < array.size(); i++){
        JsonObject o = array.get(i).getAsJsonObject();

        String type = optString(o, "type");
        VKApiAttachment attachment = parse(type, o, context);

        if(Objects.nonNull(attachment)){
            dto.entries.add(new VkApiAttachments.Entry(type, attachment));
        }
    }

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

示例6: parseMatrix

import com.google.gson.JsonParseException; //导入依赖的package包/类
public static Matrix4f parseMatrix(JsonElement e)
{
    if (!e.isJsonArray()) throw new JsonParseException("Matrix: expected an array, got: " + e);
    JsonArray m = e.getAsJsonArray();
    if (m.size() != 3) throw new JsonParseException("Matrix: expected an array of length 3, got: " + m.size());
    Matrix4f ret = new Matrix4f();
    for (int i = 0; i < 3; i++)
    {
        if (!m.get(i).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(i));
        JsonArray r = m.get(i).getAsJsonArray();
        if (r.size() != 4) throw new JsonParseException("Matrix row: expected an array of length 4, got: " + r.size());
        for (int j = 0; j < 4; j++)
        {
            try
            {
                ret.setElement(i, j, r.get(j).getAsNumber().floatValue());
            }
            catch (ClassCastException ex)
            {
                throw new JsonParseException("Matrix element: expected number, got: " + r.get(j));
            }
        }
    }
    return ret;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:26,代码来源:ForgeBlockStateV1.java

示例7: deserialize

import com.google.gson.JsonParseException; //导入依赖的package包/类
@Override
public Tweet.Image deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    try {
        if (json.isJsonObject()) {
            Tweet.Image image = new Tweet.Image();
            // The whole object is available
            final JsonObject jsonObject = json.getAsJsonObject();
            image.setThumb(context.<String>deserialize(jsonObject.get("thumb"), String.class));
            image.setHref(context.<String>deserialize(jsonObject.get("href"), String.class));
            image.setH(context.<Integer>deserialize(jsonObject.get("h"), int.class));
            image.setW(context.<Integer>deserialize(jsonObject.get("w"), int.class));
            if (Tweet.Image.check(image))
                return image;
            else
                return null;
        }
    } catch (Exception e) {
        TLog.error("ImageJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
    }
    return null;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:22,代码来源:ImageJsonDeserializer.java

示例8: deserialize

import com.google.gson.JsonParseException; //导入依赖的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

示例9: deserialize

import com.google.gson.JsonParseException; //导入依赖的package包/类
public BlockPart deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    Vector3f vector3f = this.parsePositionFrom(jsonobject);
    Vector3f vector3f1 = this.parsePositionTo(jsonobject);
    BlockPartRotation blockpartrotation = this.parseRotation(jsonobject);
    Map<EnumFacing, BlockPartFace> map = this.parseFacesCheck(p_deserialize_3_, jsonobject);

    if (jsonobject.has("shade") && !JsonUtils.isBoolean(jsonobject, "shade"))
    {
        throw new JsonParseException("Expected shade to be a Boolean");
    }
    else
    {
        boolean flag = JsonUtils.getBoolean(jsonobject, "shade", true);
        return new BlockPart(vector3f, vector3f1, map, blockpartrotation, flag);
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:19,代码来源:BlockPart.java

示例10: deserialize

import com.google.gson.JsonParseException; //导入依赖的package包/类
@Override
public Entry deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext)
    throws JsonParseException {
    JsonObject jsonEntry = (JsonObject) json;

    JsonElement key = jsonEntry.get("key");
    JsonElement content = jsonEntry.get("content");
    JsonElement filePath = jsonEntry.get("filePath");

    if (key != null) {
        StringKey keyEntry = prepareGsonParser().fromJson(key, StringKey.class);
        JsonElement value = jsonEntry.get("value");
        if (value != null) {
            return new KeyValueEntry(keyEntry, prepareGsonParser().fromJson(value, Entry.class));
        }
    } else if (content != null) {
        StringKey stringEntry = prepareGsonParser().fromJson(content, StringKey.class);
        return new StringEntry(stringEntry);
    } else if (filePath != null) {
        String fileEntry = prepareGsonParser().fromJson(filePath, String.class);
        return new FileEntry(fileEntry);
    }

    return new StringEntry("");
}
 
开发者ID:arquillian,项目名称:arquillian-reporter,代码行数:26,代码来源:EntryJsonDeserializer.java

示例11: testProjectSerializer1

import com.google.gson.JsonParseException; //导入依赖的package包/类
@org.junit.Test
public void testProjectSerializer1() throws Exception {

    final Project project = Project.of(
        Optional.of("my-magic-tool"),
        Optional.of("my-magic-tool-lib"),
        Optional.of("MIT"),
        DependencyGroup.of(ImmutableMap.of(
            RecipeIdentifier.of("org", "my-magic-lib"),
            ExactSemanticVersion.of(SemanticVersion.of(4, 5, 6)),
            RecipeIdentifier.of("org", "some-other-lib"),
            ExactSemanticVersion.of(
                SemanticVersion.of(4, 1),
                SemanticVersion.of(4, 2)),
            RecipeIdentifier.of("org", "awesome-lib"),
            AnySemanticVersion.of())));

    final String serializedProject = Serializers.serialize(project);

    final Either<JsonParseException, Project> deserializedProject =
            Serializers.parseProject(serializedProject);

    assertEquals(Either.right(project), deserializedProject);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:25,代码来源:ProjectSerializerTest.java

示例12: deserialize

import com.google.gson.JsonParseException; //导入依赖的package包/类
@Override
public ServerOption deserialize(JsonElement json, Type arg1,
		JsonDeserializationContext arg2) throws JsonParseException {
	Gson gson = new Gson();
	final ServerOption item = gson.fromJson(json, ServerOption.class);
	setParentRecursive(item, null);			
	return item;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:9,代码来源:ServerOption.java

示例13: load

import com.google.gson.JsonParseException; //导入依赖的package包/类
/**
 * Load the cached profiles from disk
 */
public void load()
{
    BufferedReader bufferedreader = null;

    try
    {
        bufferedreader = Files.newReader(this.usercacheFile, Charsets.UTF_8);
        List<PlayerProfileCache.ProfileEntry> list = (List)this.gson.fromJson((Reader)bufferedreader, TYPE);
        this.usernameToProfileEntryMap.clear();
        this.uuidToProfileEntryMap.clear();
        this.gameProfiles.clear();

        for (PlayerProfileCache.ProfileEntry playerprofilecache$profileentry : Lists.reverse(list))
        {
            if (playerprofilecache$profileentry != null)
            {
                this.addEntry(playerprofilecache$profileentry.getGameProfile(), playerprofilecache$profileentry.getExpirationDate());
            }
        }
    }
    catch (FileNotFoundException var9)
    {
        ;
    }
    catch (JsonParseException var10)
    {
        ;
    }
    finally
    {
        IOUtils.closeQuietly((Reader)bufferedreader);
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:37,代码来源:PlayerProfileCache.java

示例14: deserialize

import com.google.gson.JsonParseException; //导入依赖的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:Notoh,项目名称:DecompiledMinecraft,代码行数:16,代码来源:PackMetadataSectionSerializer.java

示例15: handleException

import com.google.gson.JsonParseException; //导入依赖的package包/类
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof HttpException) {             //HTTP错误
        HttpException httpExc = (HttpException) e;
        ex = new ApiException(e, httpExc.code());
        ex.setMsg("网络错误");  //均视为网络错误
        return ex;
    } else if (e instanceof ServerException) {    //服务器返回的错误
        ServerException serverExc = (ServerException) e;
        ex = new ApiException(serverExc, serverExc.getCode());
        ex.setMsg(serverExc.getMsg());
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException || e instanceof MalformedJsonException) {  //解析数据错误
        ex = new ApiException(e, ANALYTIC_SERVER_DATA_ERROR);
        ex.setMsg("解析错误");
        return ex;
    } else if (e instanceof ConnectException) {//连接网络错误
        ex = new ApiException(e, CONNECT_ERROR);
        ex.setMsg("连接失败");
        return ex;
    } else if (e instanceof SocketTimeoutException) {//网络超时
        ex = new ApiException(e, TIME_OUT_ERROR);
        ex.setMsg("网络超时");
        return ex;
    } else {  //未知错误
        ex = new ApiException(e, UN_KNOWN_ERROR);
        ex.setMsg("未知错误");
        return ex;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:ExceptionEngine.java


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