本文整理汇总了Java中com.google.gson.JsonIOException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java JsonIOException.getCause方法的具体用法?Java JsonIOException.getCause怎么用?Java JsonIOException.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonIOException
的用法示例。
在下文中一共展示了JsonIOException.getCause方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import com.google.gson.JsonIOException; //导入方法依赖的package包/类
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404) return Util.emptyValueOf(type);
if (response.body() == null) return null;
Reader reader = response.body().asReader();
try {
return gson.fromJson(reader, type);
} catch (JsonIOException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
} finally {
ensureClosed(reader);
}
}
示例2: decode
import com.google.gson.JsonIOException; //导入方法依赖的package包/类
@Override
public Object decode(Response response, Type type) throws IOException {
if (void.class == type || response.body() == null) {
return null;
}
Reader reader = response.body().asReader();
try {
return gson.fromJson(reader, type);
} catch (JsonIOException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
} finally {
ensureClosed(reader);
}
}
示例3: serialize
import com.google.gson.JsonIOException; //导入方法依赖的package包/类
/**
* Serializes a list of schema.org objects.
*
* @throws JsonLdSyntaxException if the objects cannot be serialized to JSON-LD.
* @throws JsonIOException if there was a problem writing to the JSON writer.
*/
public String serialize(List<? extends Thing> objects)
throws JsonLdSyntaxException, JsonIOException {
try {
return gson.toJson(objects, thingTypeToken);
} catch (JsonIOException e) {
if (e.getCause() instanceof JsonLdSyntaxException) {
throw (JsonLdSyntaxException) e.getCause();
} else {
throw e;
}
}
}