Java Code Examples for com.google.gson.JsonSyntaxException#getCause()

The following examples show how to use com.google.gson.JsonSyntaxException#getCause() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pravega   File: K8sClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example 2
Source Project: schemaorg-java   File: JsonLdSerializer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
  }
}
 
Example 3
Source Project: che   File: DtoFactory.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
  }
}