Search in sources :

Example 46 with JsonParseException

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;
}
Also used : ArrayList(java.util.ArrayList) JsonParseException(com.google.gson.JsonParseException) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException)

Example 47 with JsonParseException

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;
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) JsonParseException(com.google.gson.JsonParseException) Nullable(javax.annotation.Nullable)

Example 48 with JsonParseException

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);
}
Also used : JsonParseException(com.google.gson.JsonParseException)

Example 49 with JsonParseException

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;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) IResource(net.minecraft.client.resources.IResource)

Example 50 with JsonParseException

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;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Matcher(java.util.regex.Matcher) Gson(com.google.gson.Gson) JsonParseException(com.google.gson.JsonParseException) Map(java.util.Map) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JsonParseException (com.google.gson.JsonParseException)66 JsonObject (com.google.gson.JsonObject)24 IOException (java.io.IOException)17 JsonElement (com.google.gson.JsonElement)15 Gson (com.google.gson.Gson)14 GsonBuilder (com.google.gson.GsonBuilder)9 Type (java.lang.reflect.Type)9 JsonArray (com.google.gson.JsonArray)7 JsonParser (com.google.gson.JsonParser)6 SocketTimeoutException (java.net.SocketTimeoutException)5 JsonDeserializationContext (com.google.gson.JsonDeserializationContext)4 UnknownHostException (java.net.UnknownHostException)4 ArrayList (java.util.ArrayList)4 Resources (android.content.res.Resources)3 TextView (android.widget.TextView)3 RutgersServerIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException)3 InputStreamReader (java.io.InputStreamReader)3 ParseException (java.text.ParseException)3 Date (java.util.Date)3 ResourceLocation (net.minecraft.util.ResourceLocation)3