com.google.gson.JsonParseException#getMessage ( )源码实例Demo

下面列出了com.google.gson.JsonParseException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openapi-generator   文件: ApiInvoker.java
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
  try{
    if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
      return JsonUtil.deserializeToList(json, cls);
    }
    else if(String.class.equals(cls)) {
      if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
        return json.substring(1, json.length() - 1);
      else
        return json;
    }
    else {
      return JsonUtil.deserializeToObject(json, cls);
    }
  }
  catch (JsonParseException e) {
    throw new ApiException(500, e.getMessage());
  }
}
 
源代码2 项目: openapi-generator   文件: ApiInvoker.java
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
  try{
    if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
      return JsonUtil.deserializeToList(json, cls);
    }
    else if(String.class.equals(cls)) {
      if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
        return json.substring(1, json.length() - 1);
      else
        return json;
    }
    else {
      return JsonUtil.deserializeToObject(json, cls);
    }
  }
  catch (JsonParseException e) {
    throw new ApiException(500, e.getMessage());
  }
}
 
源代码3 项目: ProjectAres   文件: XMLUtils.java
/**
 * Parse a piece of formatted text, which can be either plain text with legacy
 * formatting codes, or JSON chat components.
 */
public static BaseComponent parseFormattedText(@Nullable Node node, BaseComponent def) throws InvalidXMLException {
    if(node == null) return def;

    // <blah translate="x"/> is shorthand for <blah>{"translate":"x"}</blah>
    if(node.isElement()) {
        final Attribute translate = node.asElement().getAttribute("translate");
        if(translate != null) {
            return new TranslatableComponent(translate.getValue());
        }
    }

    String text = node.getValueNormalize();
    if(looksLikeJson(text)) {
        try {
            return Components.concat(ComponentSerializer.parse(node.getValue()));
        } catch(JsonParseException e) {
            throw new InvalidXMLException(e.getMessage(), node, e);
        }
    } else {
        return Components.concat(TextComponent.fromLegacyText(BukkitUtils.colorize(text)));
    }
}
 
源代码4 项目: swaggy-jenkins   文件: ApiInvoker.java
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
  try{
    if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
      return JsonUtil.deserializeToList(json, cls);
    }
    else if(String.class.equals(cls)) {
      if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
        return json.substring(1, json.length() - 1);
      else
        return json;
    }
    else {
      return JsonUtil.deserializeToObject(json, cls);
    }
  }
  catch (JsonParseException e) {
    throw new ApiException(500, e.getMessage());
  }
}
 
源代码5 项目: java-slack-sdk   文件: SamplePayloadParsingTest.java
@Test
public void readAll() throws Exception {
    SlackConfig testConfig = SlackTestConfig.get();
    Gson gson = GsonFactory.createSnakeCase(testConfig);
    List<Path> files = Files.list(Paths.get("../json-logs/samples/events")).collect(Collectors.toList());
    for (Path jsonFile : files) {
        String json = readWholeAsString(jsonFile);
        String className = jsonFile.getFileName().toString().replaceFirst("\\.json$", "");
        String fqdn = "com.slack.api.app_backend.events.payload." + className;
        Class<EventsApiPayload<?>> clazz = (Class<EventsApiPayload<?>>) Class.forName(fqdn);
        try {
            EventsApiPayload<?> payload = gson.fromJson(json, clazz);
            assertThat(payload, is(notNullValue()));
        } catch (JsonParseException e) {
            String message = "Check " + fqdn + " : " + e.getMessage();
            throw new RuntimeException(message, e);
        }
    }
}
 
源代码6 项目: swagger-aem   文件: ApiInvoker.java
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
  try{
    if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
      return JsonUtil.deserializeToList(json, cls);
    }
    else if(String.class.equals(cls)) {
      if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
        return json.substring(1, json.length() - 1);
      else
        return json;
    }
    else {
      return JsonUtil.deserializeToObject(json, cls);
    }
  }
  catch (JsonParseException e) {
    throw new ApiException(500, e.getMessage());
  }
}
 
源代码7 项目: zeppelin   文件: GCSNotebookRepo.java
@Override
public Note get(String noteId, String notePath, AuthenticationInfo subject) throws IOException {
  BlobId blobId = makeBlobId(noteId, notePath);
  byte[] contents;
  try {
    contents = storage.readAllBytes(blobId);
  } catch (StorageException se) {
    throw new IOException("Could not read " + blobId.toString() + ": " + se.getMessage(), se);
  }

  try {
    return Note.fromJson(new String(contents, encoding));
  } catch (JsonParseException jpe) {
    throw new IOException(
        "Could note parse as json " + blobId.toString() + jpe.getMessage(), jpe);
  }
}
 
源代码8 项目: zeppelin   文件: OldGCSNotebookRepo.java
@Override
public Note get(String noteId, AuthenticationInfo subject) throws IOException {
  BlobId blobId = makeBlobId(noteId);
  byte[] contents;
  try {
    contents = storage.readAllBytes(blobId);
  } catch (StorageException se) {
    throw new IOException("Could not read " + blobId.toString() + ": " + se.getMessage(), se);
  }

  try {
    return Note.fromJson(new String(contents, encoding));
  } catch (JsonParseException jpe) {
    throw new IOException(
        "Could note parse as json " + blobId.toString() + jpe.getMessage(), jpe);
  }
}
 
源代码9 项目: lams   文件: GsonHttpMessageConverter.java
private Object readTypeToken(TypeToken<?> token, HttpInputMessage inputMessage) throws IOException {
	Reader json = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders()));
	try {
		return this.gson.fromJson(json, token.getType());
	}
	catch (JsonParseException ex) {
		throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
	}
}
 
@Override
public AuthenticationResponse handleResponse(final HttpResponse response) throws IOException {
    if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        Charset charset = HTTP.DEF_CONTENT_CHARSET;
        ContentType contentType = ContentType.get(response.getEntity());
        if(contentType != null) {
            if(contentType.getCharset() != null) {
                charset = contentType.getCharset();
            }
        }
        try {
            final JsonObject json = JsonParser.parseReader(new InputStreamReader(response.getEntity().getContent(), charset)).getAsJsonObject();
            final String token = json.getAsJsonPrimitive("token").getAsString();
            final String endpoint = json.getAsJsonPrimitive("endpoint").getAsString();
            return new AuthenticationResponse(response, token,
                    Collections.singleton(new Region(null, URI.create(endpoint), null, true)));
        }
        catch(JsonParseException e) {
            throw new IOException(e.getMessage(), e);
        }
    }
    else if(response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED
            || response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN) {
        throw new AuthorizationException(new Response(response));
    }
    throw new GenericException(new Response(response));
}
 
private Object readTypeToken(TypeToken<?> token, HttpInputMessage inputMessage) throws IOException {
	Reader json = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders()));
	try {
		return this.gson.fromJson(json, token.getType());
	}
	catch (JsonParseException ex) {
		throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex);
	}
}
 
源代码12 项目: MOE   文件: ProjectConfig.java
public static ProjectConfig parse(String configText) throws InvalidProject {
  ProjectConfig config = null;
  if (configText != null) {
    try {
      JsonReader configReader = new JsonReader(new StringReader(configText));
      configReader.setLenient(true);
      JsonElement configJsonElement = new JsonParser().parse(configReader);
      if (configJsonElement != null) {
        // Config files often contain JavaScript idioms like comments, single quoted strings,
        // and trailing commas in lists.
        // Check that the JSON parsed from configText is structurally the same as that
        // produced when it is interpreted by GSON in lax mode.
        String normalConfigText = JsonSanitizer.sanitize(configText);
        JsonElement normalConfigJsonElement = new JsonParser().parse(normalConfigText);
        JsonStructureChecker.requireSimilar(configJsonElement, normalConfigJsonElement);

        Gson gson = GsonModule.provideGson(); // TODO(user): Remove this static reference.
        config = gson.fromJson(configText, ProjectConfig.class);
      }
    } catch (JsonParseException e) {
      throw new InvalidProject(e, "Could not parse MOE config: " + e.getMessage());
    }
  }

  if (config == null) {
    throw new InvalidProject("Could not parse MOE config");
  }
  config.validate();
  return config;
}
 
源代码13 项目: smarthome   文件: HueBridge.java
private <T> T safeFromJson(String json, Type typeOfT) throws ApiException {
    try {
        return gson.fromJson(json, typeOfT);
    } catch (JsonParseException e) {
        throw new ApiException("API returned unexpected result: " + e.getMessage());
    }
}
 
源代码14 项目: smarthome   文件: HueBridge.java
private <T> T safeFromJson(String json, Class<T> classOfT) throws ApiException {
    try {
        return gson.fromJson(json, classOfT);
    } catch (JsonParseException e) {
        throw new ApiException("API returned unexpected result: " + e.getMessage());
    }
}
 
源代码15 项目: WebIDE-Backend   文件: GsonMessageConverter.java
@Override
public Object convertFromInternal(Message<?> message, Class<?> targetClass) {

    TypeToken<?> token = getTypeToken(targetClass);

    Object payload = message.getPayload();

    Charset charset = getCharset(getMimeType(message.getHeaders()));

    Reader reader;

    if (payload instanceof byte[]) {
        reader = new InputStreamReader(new ByteArrayInputStream((byte[]) payload), charset);
    } else {
        reader = new StringReader((String) payload);
    }

    try {

        return this.gson.fromJson(reader, token.getType());

    } catch (JsonParseException ex) {
        throw new MessageConversionException(message, "Could not read JSON: " + ex.getMessage(), ex);
    }
}
 
 同类方法