use of com.google.gson.JsonParseException in project immutables by immutables.
the class ExpectedSubtypesAdapter method read.
// safe unchecked. expected that supplied adapters are producing correct types
// enforced by constructor parameters.
@SuppressWarnings("unchecked")
@Override
public T read(JsonReader in) throws IOException {
List<Exception> exceptions = new ArrayList<>(subtypes.length);
ReaderSupplier readerSupplier = readForSupplier(in);
for (TypeAdapter<?> typeAdapter : adapters) {
try {
return (T) typeAdapter.read(readerSupplier.create());
} catch (Exception ex) {
exceptions.add(ex);
}
}
JsonParseException failure = new JsonParseException(String.format("Cannot parse %s with following subtypes: %s", type, Arrays.toString(subtypes)));
for (Exception exception : exceptions) {
failure.addSuppressed(exception);
}
throw failure;
}
use of com.google.gson.JsonParseException in project MinecraftForge by MinecraftForge.
the class ForgeHooks method loadLootTable.
@Nullable
public static LootTable loadLootTable(Gson gson, ResourceLocation name, String data, boolean custom) {
Deque<LootTableContext> que = lootContext.get();
if (que == null) {
que = Queues.newArrayDeque();
lootContext.set(que);
}
LootTable ret = null;
try {
que.push(new LootTableContext(name, custom));
ret = gson.fromJson(data, LootTable.class);
que.pop();
} catch (JsonParseException e) {
que.pop();
throw e;
}
if (!custom)
ret = ForgeEventFactory.loadLootTable(name, ret);
if (ret != null)
ret.freeze();
return ret;
}
use of com.google.gson.JsonParseException in project MinecraftForge by MinecraftForge.
the class ForgeHooks method readPoolName.
public static String readPoolName(JsonObject json) {
LootTableContext ctx = ForgeHooks.getLootTableContext();
ctx.resetPoolCtx();
if (json.has("name"))
return JsonUtils.getString(json, "name");
if (ctx.custom)
//We don't care about custom ones modders shouldn't be editing them!
return "custom#" + json.hashCode();
ctx.poolCount++;
if (!ctx.vanilla)
throw new JsonParseException("Loot Table \"" + ctx.name.toString() + "\" Missing `name` entry for pool #" + (ctx.poolCount - 1));
return ctx.poolCount == 1 ? "main" : "pool" + (ctx.poolCount - 1);
}
use of com.google.gson.JsonParseException in project MinecraftForge by MinecraftForge.
the class ModelBlockAnimation method loadVanillaAnimation.
/**
* Load armature associated with a vanilla model.
*/
public static ModelBlockAnimation loadVanillaAnimation(IResourceManager manager, ResourceLocation armatureLocation) {
try {
IResource resource = null;
try {
resource = manager.getResource(armatureLocation);
} catch (FileNotFoundException e) {
// this is normal. FIXME: error reporting?
return defaultModelBlockAnimation;
}
ModelBlockAnimation mba = mbaGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), ModelBlockAnimation.class);
//String json = mbaGson.toJson(mba);
return mba;
} catch (IOException e) {
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
return defaultModelBlockAnimation;
} catch (JsonParseException e) {
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
return defaultModelBlockAnimation;
}
}
use of com.google.gson.JsonParseException in project intellij-community by JetBrains.
the class ResourceRootFilter method getProperties.
@NotNull
public Map<Object, Object> getProperties() {
if (propertiesMap == null) {
try {
Gson gson = new GsonBuilder().create();
propertiesMap = gson.fromJson(properties, new TypeToken<Map<Object, Object>>() {
}.getType());
if ("RenamingCopyFilter".equals(filterType)) {
final Object pattern = propertiesMap.get("pattern");
final Matcher matcher = Pattern.compile(pattern instanceof String ? (String) pattern : "").matcher("");
propertiesMap.put("matcher", matcher);
}
} catch (JsonParseException e) {
throw new RuntimeException("Unsupported filter: " + properties, e);
}
if (propertiesMap == null) {
propertiesMap = new HashMap<>();
}
}
return propertiesMap;
}
Aggregations