Search in sources :

Example 96 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.

the class JsonVariableModel method deserializePartArray.

static JsonVariableModelPart[] deserializePartArray(JsonObject json, String member, FunctionContext fnCtx, ResourceLoaderContext ctx, boolean require) {
    if (!json.has(member)) {
        if (require) {
            throw new JsonSyntaxException("Did not have '" + member + "' in '" + json + "'");
        } else {
            return new JsonVariableModelPart[0];
        }
    }
    JsonElement elem = json.get(member);
    if (!elem.isJsonArray()) {
        throw new JsonSyntaxException("Expected an array, got '" + elem + "'");
    }
    JsonArray array = elem.getAsJsonArray();
    JsonVariableModelPart[] to = new JsonVariableModelPart[array.size()];
    for (int i = 0; i < to.length; i++) {
        to[i] = JsonVariableModelPart.deserializeModelPart(array.get(i), fnCtx, ctx);
    }
    return to;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement)

Example 97 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.

the class JsonVariableModel method deserializeTextures.

private void deserializeTextures(JsonElement elem) {
    if (elem == null)
        return;
    if (!elem.isJsonObject()) {
        throw new JsonSyntaxException("Expected to find an object for 'textures', but found " + elem);
    }
    JsonObject obj = elem.getAsJsonObject();
    for (Entry<String, JsonElement> entry : obj.entrySet()) {
        String name = entry.getKey();
        JsonElement tex = entry.getValue();
        JsonTexture texture;
        if (tex.isJsonPrimitive() && tex.getAsJsonPrimitive().isString()) {
            String location = tex.getAsString();
            texture = new JsonTexture(location);
        } else if (tex.isJsonObject()) {
            texture = new JsonTexture(tex.getAsJsonObject());
        } else {
            throw new JsonSyntaxException("Expected a string or an object, but got " + tex);
        }
        textures.put(name, texture);
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 98 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.

the class ElementType method resolvePosition.

public static IGuiPosition resolvePosition(JsonGuiElement json, String name, IGuiPosition parent, FunctionContext ctx) {
    String eqn = json.properties.get(name);
    if (eqn == null) {
        INodeDouble x = getEquationDouble(json, name + "[0]", ctx);
        INodeDouble y = getEquationDouble(json, name + "[1]", ctx);
        return IGuiPosition.create(x, y).offset(parent);
    }
    try {
        return GenericExpressionCompiler.compileExpressionObject(IGuiPosition.class, eqn, ctx).evaluate();
    } catch (InvalidExpressionException e) {
        throw new JsonSyntaxException("Failed to resolve a position for " + json.fullName, e);
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble) IGuiPosition(buildcraft.lib.gui.pos.IGuiPosition)

Example 99 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.

the class ElementType method resolveArea.

public static IGuiArea resolveArea(JsonGuiElement json, String name, IGuiPosition parent, FunctionContext ctx) {
    String eqn = json.properties.get(name);
    if (eqn == null) {
        INodeDouble x = getEquationDouble(json, name + "[0]", ctx);
        INodeDouble y = getEquationDouble(json, name + "[1]", ctx);
        INodeDouble w = getEquationDouble(json, name + "[2]", ctx);
        INodeDouble h = getEquationDouble(json, name + "[3]", ctx);
        return IGuiArea.create(x, y, w, h).offset(parent);
    }
    try {
        return GenericExpressionCompiler.compileExpressionObject(IGuiArea.class, eqn, ctx).evaluate();
    } catch (InvalidExpressionException e) {
        throw new JsonSyntaxException("Failed to resolve an area for " + json.fullName, e);
    }
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) JsonSyntaxException(com.google.gson.JsonSyntaxException) InvalidExpressionException(buildcraft.lib.expression.api.InvalidExpressionException) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble)

Example 100 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project BuildCraft by BuildCraft.

the class GuiConfigManager method loadFromConfigFile.

public static void loadFromConfigFile() {
    if (BCLibConfig.guiConfigFile != null) {
        Gson gson = new Gson();
        List<String> lines;
        try {
            lines = Files.readAllLines(BCLibConfig.guiConfigFile.toPath());
        } catch (IOException io) {
            BCLog.logger.warn("[lib.gui.cfg] Failed to read the config file! " + io.getMessage());
            return;
        }
        StringBuilder allLines = new StringBuilder();
        for (String line : lines) {
            allLines.append(line);
            allLines.append('\n');
        }
        try {
            readFromJson(gson.fromJson(allLines.toString(), JsonObject.class));
            return;
        } catch (JsonSyntaxException jse) {
            BCLog.logger.warn("[lib.gui.cfg] There's a problem with the config file: try fixing it manually, " + "or deleting it to let buildcraft overwrite it on save." + jse.getMessage());
        } catch (ClassCastException cce) {
            // This happens occasionally, and its a bit wierd
            BCLog.logger.warn("[lib.gui.cfg] There's a major problem with the config file: try fixing it manually, " + "or deleting it to let buildcraft overwrite it on save." + cce.getMessage());
        }
        BCLog.logger.info("File contents:");
        for (String line : lines) {
            BCLog.logger.info(line.replace("\0", "\\0"));
        }
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)379 Gson (com.google.gson.Gson)169 IOException (java.io.IOException)83 HashMap (java.util.HashMap)68 JsonElement (com.google.gson.JsonElement)62 JsonObject (com.google.gson.JsonObject)58 ArrayList (java.util.ArrayList)46 JsonParser (com.google.gson.JsonParser)42 GsonBuilder (com.google.gson.GsonBuilder)38 Cursor (android.database.Cursor)33 InputStreamReader (java.io.InputStreamReader)30 Map (java.util.Map)30 BadRequestException (co.cask.cdap.common.BadRequestException)28 JsonArray (com.google.gson.JsonArray)28 Path (javax.ws.rs.Path)28 Reader (java.io.Reader)26 Type (java.lang.reflect.Type)23 JsonIOException (com.google.gson.JsonIOException)21 FileReader (java.io.FileReader)21 File (java.io.File)19