use of com.google.gson.JsonParseException in project incubator-gobblin by apache.
the class DatasetDescriptorImpl method setComplianceField.
private void setComplianceField() {
Preconditions.checkArgument(this.complianceFieldPath.isPresent());
try {
JsonObject descriptorObject = new JsonParser().parse(this.descriptor).getAsJsonObject();
List<String> list = DOT_SPLITTER.splitToList(this.complianceFieldPath.get());
for (int i = 0; i < list.size() - 1; i++) {
descriptorObject = descriptorObject.getAsJsonObject(list.get(i));
}
this.complianceField = descriptorObject.get(list.get(list.size() - 1)).getAsString();
} catch (JsonParseException | NullPointerException e) {
log.warn("Compliance field not found at path " + this.complianceFieldPath.get() + " in the descriptor " + this.descriptor);
Throwables.propagate(e);
}
}
use of com.google.gson.JsonParseException in project id4i-api_client-java by BlueRainSoftware.
the class JSON method deserialize.
/**
* Deserialize the given JSON string to Java object.
*
* @param <T> Type
* @param body The JSON string
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(String body, Type returnType) {
try {
if (isLenientOnJson) {
JsonReader jsonReader = new JsonReader(new StringReader(body));
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
return gson.fromJson(body, returnType);
}
} catch (JsonParseException e) {
// return the response body string directly for the String return type;
if (returnType.equals(String.class))
return (T) body;
else
throw (e);
}
}
use of com.google.gson.JsonParseException in project BaseProject by wareine.
the class ExceptionHandle method handleException.
public static ResponseException handleException(Throwable e) {
ResponseException ex;
if (e instanceof HttpException) {
HttpException httpException = (HttpException) e;
ex = new ResponseException(e, ERROR.HTTP_ERROR);
switch(httpException.code()) {
case UNAUTHORIZED:
case FORBIDDEN:
case NOT_FOUND:
case REQUEST_TIMEOUT:
case GATEWAY_TIMEOUT:
case INTERNAL_SERVER_ERROR:
case BAD_GATEWAY:
case SERVICE_UNAVAILABLE:
default:
ex.message = "网络错误";
break;
}
return ex;
} else if (e instanceof ServerException) {
ServerException resultException = (ServerException) e;
ex = new ResponseException(resultException, resultException.code);
ex.message = resultException.message;
return ex;
} else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) {
ex = new ResponseException(e, ERROR.PARSE_ERROR);
ex.message = "解析错误";
return ex;
} else if (e instanceof ConnectException) {
ex = new ResponseException(e, ERROR.NETWORD_ERROR);
ex.message = "连接失败";
return ex;
} else if (e instanceof javax.net.ssl.SSLHandshakeException) {
ex = new ResponseException(e, ERROR.SSL_ERROR);
ex.message = "证书验证失败";
return ex;
} else if (e instanceof ConnectTimeoutException) {
ex = new ResponseException(e, ERROR.TIMEOUT_ERROR);
ex.message = "连接超时";
return ex;
} else if (e instanceof java.net.SocketTimeoutException) {
ex = new ResponseException(e, ERROR.TIMEOUT_ERROR);
ex.message = "连接超时";
return ex;
} else {
ex = new ResponseException(e, ERROR.UNKNOWN);
ex.message = "未知错误";
return ex;
}
}
use of com.google.gson.JsonParseException in project cdap by caskdata.
the class ProtoConstraintCodec method deserialize.
@Override
public ProtoConstraint deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json == null) {
return null;
}
if (!(json instanceof JsonObject)) {
throw new JsonParseException("Expected a JsonObject but found a " + json.getClass().getName());
}
JsonObject object = (JsonObject) json;
JsonElement typeJson = object.get("type");
ProtoConstraint.Type constraintType = context.deserialize(typeJson, ProtoConstraint.Type.class);
Class<? extends ProtoConstraint> subClass = typeClassMap.get(constraintType);
if (subClass == null) {
throw new JsonParseException("Unable to map constraint type " + constraintType + " to a run constraint class");
}
ProtoConstraint constraint = context.deserialize(json, subClass);
constraint.validate();
return constraint;
}
use of com.google.gson.JsonParseException in project be5 by DevelopmentOnTheEdge.
the class HashLink method parse.
public static HashLink parse(String code) {
try {
JsonObject parsed = new JsonParser().parse(code).getAsJsonObject();
String action = parsed.get("action").getAsString();
Map<String, String> namedArgs = getNamedArgs(parsed);
List<String> positionalArgs = getPositionalArgs(parsed);
return new HashLink(action, positionalArgs, namedArgs);
} catch (IllegalStateException | ClassCastException e) {
throw new IllegalArgumentException(e);
} catch (JsonParseException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations