本文整理汇总了Java中com.google.gson.JsonParseException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParseException.getMessage方法的具体用法?Java JsonParseException.getMessage怎么用?Java JsonParseException.getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonParseException
的用法示例。
在下文中一共展示了JsonParseException.getMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.google.gson.JsonParseException; //导入方法依赖的package包/类
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: parseFormattedText
import com.google.gson.JsonParseException; //导入方法依赖的package包/类
/**
* 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)));
}
}
示例3: readTypeToken
import com.google.gson.JsonParseException; //导入方法依赖的package包/类
private Object readTypeToken(TypeToken<?> token, HttpInputMessage inputMessage) throws IOException {
InputStreamReader json = new InputStreamReader(inputMessage.getBody(), this.getCharset(inputMessage.getHeaders()));
try {
return this.gson.fromJson(json, token.getType());
} catch (JsonParseException var5) {
throw new HttpMessageNotReadableException("JSON parse error: " + var5.getMessage(), var5);
}
}
示例4: handleResponse
import com.google.gson.JsonParseException; //导入方法依赖的package包/类
@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 JsonParser parser = new JsonParser();
final JsonObject json = parser.parse(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));
}
示例5: readObject
import com.google.gson.JsonParseException; //导入方法依赖的package包/类
private Object readObject(HttpInputMessage inputMessage, TypeToken<?> token) throws IOException {
try (Reader json = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders()))) {
return this.gsonForReader.fromJson(json, token.getType());
} catch (JsonParseException ex) {
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
}
}
示例6: convertJsonToReportPojos
import com.google.gson.JsonParseException; //导入方法依赖的package包/类
public Report[] convertJsonToReportPojos(final String json) throws CluecumberPluginException {
Report[] reports = null;
try {
reports = gsonParser.fromJson(json, Report[].class);
} catch (JsonParseException e) {
throw new CluecumberPluginException(e.getMessage());
}
return reports;
}