use of com.google.gson.JsonParseException in project gerrit by GerritCodeReview.
the class EditDeserializer method get.
private static int get(final JsonArray a, final int idx) throws JsonParseException {
final JsonElement v = a.get(idx);
if (!v.isJsonPrimitive()) {
throw new JsonParseException("Expected array of 4 for Edit type");
}
final JsonPrimitive p = (JsonPrimitive) v;
if (!p.isNumber()) {
throw new JsonParseException("Expected array of 4 for Edit type");
}
return p.getAsInt();
}
use of com.google.gson.JsonParseException in project gerrit by GerritCodeReview.
the class EditDeserializer method deserialize.
@Override
public Edit deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonNull()) {
return null;
}
if (!json.isJsonArray()) {
throw new JsonParseException("Expected array for Edit type");
}
final JsonArray o = (JsonArray) json;
final int cnt = o.size();
if (cnt < 4 || cnt % 4 != 0) {
throw new JsonParseException("Expected array of 4 for Edit type");
}
if (4 == cnt) {
return new Edit(get(o, 0), get(o, 1), get(o, 2), get(o, 3));
}
List<Edit> l = new ArrayList<>((cnt / 4) - 1);
for (int i = 4; i < cnt; ) {
int as = get(o, i++);
int ae = get(o, i++);
int bs = get(o, i++);
int be = get(o, i++);
l.add(new Edit(as, ae, bs, be));
}
return new ReplaceEdit(get(o, 0), get(o, 1), get(o, 2), get(o, 3), l);
}
use of com.google.gson.JsonParseException in project gerrit by GerritCodeReview.
the class SupplierDeserializer method deserialize.
@Override
public Supplier<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
checkArgument(typeOfT instanceof ParameterizedType);
ParameterizedType parameterizedType = (ParameterizedType) typeOfT;
if (parameterizedType.getActualTypeArguments().length != 1) {
throw new JsonParseException("Expected one parameter type in Supplier interface.");
}
Type supplierOf = parameterizedType.getActualTypeArguments()[0];
return Suppliers.ofInstance(context.deserialize(json, supplierOf));
}
use of com.google.gson.JsonParseException in project gerrit by GerritCodeReview.
the class EventDeserializer method deserialize.
@Override
public Event deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonObject()) {
throw new JsonParseException("Not an object");
}
JsonElement typeJson = json.getAsJsonObject().get("type");
if (typeJson == null || !typeJson.isJsonPrimitive() || !typeJson.getAsJsonPrimitive().isString()) {
throw new JsonParseException("Type is not a string: " + typeJson);
}
String type = typeJson.getAsJsonPrimitive().getAsString();
Class<?> cls = EventTypes.getClass(type);
if (cls == null) {
throw new JsonParseException("Unknown event type: " + type);
}
return context.deserialize(json, cls);
}
use of com.google.gson.JsonParseException in project wh-app-android by WhiteHouse.
the class DateFormatter method deserialize.
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonParseException exception = null;
final String value = json.getAsString();
for (DateFormat format : formats) {
try {
synchronized (format) {
return format.parse(value);
}
} catch (ParseException e) {
exception = new JsonParseException(e);
}
}
throw exception;
}
Aggregations