use of com.google.gson.JsonParseException in project Bookshelf by Darkhax-Minecraft.
the class SerializerBlockState method read.
@Override
public BlockState read(JsonElement json) {
if (json.isJsonObject()) {
final JsonObject obj = json.getAsJsonObject();
final Block block = Serializers.BLOCK.read(obj, "block");
BlockState state = block.defaultBlockState();
if (obj.has("properties")) {
final JsonElement properties = obj.get("properties");
for (final Entry<String, JsonElement> property : properties.getAsJsonObject().entrySet()) {
state = this.readProperty(state, property.getKey(), property.getValue());
}
}
return state;
} else {
throw new JsonParseException("Expected properties to be an object. Recieved " + JSONUtils.getType(json));
}
}
use of com.google.gson.JsonParseException in project intellij-plugins by StepicOrg.
the class ReplyDeserializer method deserialize.
@Override
public Reply deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json == null || !(json instanceof JsonObject)) {
return null;
}
Reply reply = new Reply();
JsonObject object = json.getAsJsonObject();
String language = getString(object, "language");
reply.setLanguage(language);
String code = getString(object, "code");
reply.setCode(code);
String formula = getString(object, "formula");
reply.setFormula(formula);
String text = getString(object, "text");
reply.setText(text);
String number = getString(object, "number");
reply.setNumber(number);
JsonArray ordering = getJsonArray(object, "ordering");
if (ordering != null) {
List<Integer> intOrdering = new ArrayList<>();
ordering.forEach(item -> intOrdering.add(item.getAsInt()));
reply.setOrdering(intOrdering);
}
reply.setAttachments(getList(object, "attachments", (jsonElement) -> context.deserialize(jsonElement, Attachment.class)));
reply.setFiles(getStringList(object, "files"));
JsonArray choices = getJsonArray(object, "choices");
if (choices != null && choices.size() > 0) {
if (choices.get(0).isJsonPrimitive()) {
List<Boolean> list = new ArrayList<>();
choices.forEach(item -> list.add(item.getAsBoolean()));
reply.setChoices(list);
} else {
List<Choice> list = new ArrayList<>();
choices.forEach(item -> list.add(context.deserialize(item, Choice.class)));
reply.setChoices(list);
}
}
reply.setBlanks(getStringList(object, "blanks"));
return reply;
}
use of com.google.gson.JsonParseException in project ninja by ninjaframework.
the class ApiControllerDocTesterTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// Creates the json object which will manage the information received
GsonBuilder builder = new GsonBuilder();
// Register an adapter to manage the date types as long values
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
use of com.google.gson.JsonParseException in project ninja by ninjaframework.
the class ApiControllerTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// Creates the json object which will manage the information received
GsonBuilder builder = new GsonBuilder();
// Register an adapter to manage the date types as long values
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
use of com.google.gson.JsonParseException in project ninja by ninjaframework.
the class ApiControllerDocTest method getGsonWithLongToDateParsing.
private Gson getGsonWithLongToDateParsing() {
// Creates the json object which will manage the information received
GsonBuilder builder = new GsonBuilder();
// Register an adapter to manage the date types as long values
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
return gson;
}
Aggregations