下面列出了com.google.gson.JsonSyntaxException#getCause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Delete persistent volume claim.
* @param namespace Namespace.
* @param name Persistent volume claim name.
*/
@SneakyThrows(ApiException.class)
public void deletePVC(String namespace, String name) {
CoreV1Api api = new CoreV1Api();
try {
api.deleteNamespacedPersistentVolumeClaim(name, namespace, PRETTY_PRINT, DRY_RUN, null, null, null, new V1DeleteOptions());
} catch (JsonSyntaxException e) {
// https://github.com/kubernetes-client/java/issues/86
if (e.getCause() instanceof IllegalStateException) {
IllegalStateException ise = (IllegalStateException) e.getCause();
if (ise.getMessage() != null && ise.getMessage().contains("Expected a string but was BEGIN_OBJECT")) {
log.debug("Ignoring exception", e);
return;
}
}
throw e;
}
}
/**
* Deserialized the JSON-LD string into schema.org objects.
*
* @throws JsonLdSyntaxException if the JSON-LD string could not be deserialized to schema.org
* types.
* @throws JsonSyntaxException if the JSON-LD string has JSON syntax error.
*/
public List<Thing> deserialize(String json) throws JsonLdSyntaxException, JsonSyntaxException {
try {
return gson.fromJson(json, thingTypeToken);
} catch (JsonSyntaxException e) {
if (e.getCause() instanceof JsonLdSyntaxException) {
throw (JsonLdSyntaxException) e.getCause();
} else {
throw e;
}
}
}
/**
* Parse a JSON string that contains DTOs, propagating JSON exceptions correctly if they are
* caused by failures in the given Reader. Real JSON syntax exceptions are propagated as-is.
*/
private <T> T parseDto(Reader json, Type type) throws IOException {
try {
return dtoGson.fromJson(json, type);
} catch (JsonSyntaxException e) {
final Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw e;
}
}