本文整理匯總了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;
}
}
}