Example usage for com.google.gson JsonParseException JsonParseException

List of usage examples for com.google.gson JsonParseException JsonParseException

Introduction

In this page you can find the example usage for com.google.gson JsonParseException JsonParseException.

Prototype

public JsonParseException(Throwable cause) 

Source Link

Document

Creates exception with the specified cause.

Usage

From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.MapperPayloadOrAttributeDeserializer.java

License:Open Source License

@Override
public Object deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) {
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(TYPE);
    String mapperAttributeType = jsonPrimitive.getAsString();
    if (mapperAttributeType.equalsIgnoreCase(MapperPayloadOrAttributeType.LIST.toString())) {
        return jsonDeserializationContext.deserialize(jsonObject, MapperListPayloadOrAttribute.class);
    } else if (mapperAttributeType.equalsIgnoreCase(MapperPayloadOrAttributeType.MAP.toString())) {
        return jsonDeserializationContext.deserialize(jsonObject, MapperMapPayloadOrAttribute.class);
    }/*from  w ww .j av  a  2 s  .c om*/
    throw new JsonParseException(
            "Unable to de-serialize the Mapper Attribute/Payload JSON since its type is unknown");
}

From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.QueryInputConfigDeSerializer.java

License:Open Source License

@Override
public Object deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) {
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(TYPE);
    String queryInputType = jsonPrimitive.getAsString();
    if (queryInputType.equalsIgnoreCase(QueryInputType.WINDOW.toString())
            || queryInputType.equalsIgnoreCase(QueryInputType.FILTER.toString())
            || queryInputType.equalsIgnoreCase(QueryInputType.PROJECTION.toString())
            || queryInputType.equalsIgnoreCase(QueryInputType.FUNCTION.toString())) {
        return jsonDeserializationContext.deserialize(jsonObject, WindowFilterProjectionConfig.class);
    } else if (queryInputType.equalsIgnoreCase(QueryInputType.JOIN.toString())) {
        return jsonDeserializationContext.deserialize(jsonObject, JoinConfig.class);
    } else if (queryInputType.equalsIgnoreCase(QueryInputType.PATTERN.toString())
            || queryInputType.equalsIgnoreCase(QueryInputType.SEQUENCE.toString())) {
        return jsonDeserializationContext.deserialize(jsonObject, PatternSequenceConfig.class);
    }/*  ww  w  . ja va 2s .com*/
    throw new JsonParseException("Unable to de-serialize the QueryInputConfig JSON since its type is unknown");
}

From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.QueryOutputConfigDeSerializer.java

License:Open Source License

@Override
public Object deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) {
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(TYPE);
    if (jsonPrimitive == null) {
        throw new JsonParseException("Unable to find type of the QueryOutputConfig");
    }//from  w ww  .  j a v a 2  s.  c  o m
    String queryOutputType = jsonPrimitive.getAsString();
    if (jsonObject.get(TARGET) == null) {
        return null;
    }
    String target = jsonObject.get(TARGET).getAsString();
    if (queryOutputType.equalsIgnoreCase(QueryOutputType.INSERT.toString())) {
        return new QueryOutputConfig(queryOutputType,
                jsonDeserializationContext.deserialize(jsonObject.get(OUTPUT), InsertOutputConfig.class),
                target);
    } else if (queryOutputType.equalsIgnoreCase(QueryOutputType.UPDATE.toString())) {
        return new QueryOutputConfig(queryOutputType, jsonDeserializationContext
                .deserialize(jsonObject.get(OUTPUT), UpdateInsertIntoOutputConfig.class), target);
    } else if (queryOutputType.equalsIgnoreCase(QueryOutputType.UPDATE_OR_INSERT_INTO.toString())) {
        return new QueryOutputConfig(queryOutputType, jsonDeserializationContext
                .deserialize(jsonObject.get(OUTPUT), UpdateInsertIntoOutputConfig.class), target);
    } else if (queryOutputType.equalsIgnoreCase(QueryOutputType.DELETE.toString())) {
        return new QueryOutputConfig(queryOutputType,
                jsonDeserializationContext.deserialize(jsonObject.get(OUTPUT), DeleteOutputConfig.class),
                target);
    }
    throw new JsonParseException("Unable to de-serialize the QueryOutputConfig JSON since its type is unknown");
}

From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.StreamHandlerConfigDeserializer.java

License:Open Source License

@Override
public Object deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) {
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(TYPE);
    String streamHandlerType = jsonPrimitive.getAsString();
    if (streamHandlerType.equalsIgnoreCase(StreamHandlerType.FILTER.toString())) {
        return jsonDeserializationContext.deserialize(jsonObject, FilterConfig.class);
    } else if (streamHandlerType.equalsIgnoreCase(StreamHandlerType.FUNCTION.toString())
            || streamHandlerType.equalsIgnoreCase(StreamHandlerType.WINDOW.toString())) {
        return jsonDeserializationContext.deserialize(jsonObject, FunctionWindowConfig.class);
    }//  w  w w .ja  v  a 2  s.  co m
    throw new JsonParseException(
            "Unable to de-serialize the StreamHandlerConfig JSON since its type is unknown");
}

From source file:org.xacml4j.v30.marshal.json.CategoryAdapter.java

License:Open Source License

@Override
public Category deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    try {//  w ww  .  j a va  2s  .com
        JsonObject o = json.getAsJsonObject();
        String categoryId = GsonUtil.getAsString(o, JsonProperties.CATEGORY_ID_PROPERTY, null);
        Preconditions.checkState(categoryId != null);
        CategoryId category = SHORT_NAMES.get(categoryId);
        category = (category == null) ? Categories.parse(categoryId) : category;
        String id = GsonUtil.getAsString(o, JsonProperties.ID_PROPERTY, null);
        Collection<Attribute> attr = context.deserialize(o.getAsJsonArray(JsonProperties.ATTRIBUTE_PROPERTY),
                new TypeToken<Collection<Attribute>>() {
                }.getType());
        Node content = DOMUtil.stringToNode(GsonUtil.getAsString(o, JsonProperties.CONTENT_PROPERTY, null));
        return Category.builder(category).id(id)
                .entity(Entity.builder().attributes(attr).content(content).build()).build();
    } catch (XacmlSyntaxException e) {
        throw new JsonParseException(e);
    }
}

From source file:org.xacml4j.v30.marshal.json.ResultAdapter.java

License:Open Source License

@Override
public Result deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject o = json.getAsJsonObject();
    final String decisionValue = GsonUtil.getAsString(o, DECISION_PROPERTY, null);
    Decision decision = DECISION_VALUE_MAP.inverse().get(decisionValue);
    if (decision == null) {
        throw new JsonParseException(String.format("Invalid 'Decision' value: \"%s\"", decisionValue));
    }//from   ww  w .  j a  va  2 s. c o m
    Status status = context.deserialize(o.get(STATUS_PROPERTY), Status.class);

    Result.Builder builder = Result.builder(decision, status);

    Collection<Obligation> obligations = context.deserialize(o.get(OBLIGATIONS_PROPERTY), OBLIGATIONS_TYPE);
    if (obligations != null) {
        checkArgument(!obligations.isEmpty(), "At least one obligation should be specified.");
        builder.obligation(obligations);
    }

    Collection<Advice> advice = context.deserialize(o.get(ASSOCIATED_ADVICE_PROPERTY), ADVICE_TYPE);
    if (advice != null) {
        checkArgument(!advice.isEmpty(), "At least one advice should be specified.");
        builder.advice(advice);
    }

    Collection<Category> attributes = context.deserialize(o.get(ATTRIBUTES_PROPERTY), ATTRIBUTES_TYPE);
    if (attributes != null) {
        builder.includeInResultAttr(attributes);
    }
    deserializePolicyIdentifiers(o, context, builder);
    return builder.build();
}

From source file:plasticfantastic.ValidatedCardFactory.java

License:Apache License

/**
 * Parse the JSON output of a {@link Reader} a into a factory.
 * <p>//w  ww  . j  a v  a2s .  c  om
 * See {@link ValidatedCardFactory} for details of the expected JSON structure.
 *
 * @param reader which provides the JSON to be parsed
 * @return a new factory, initialised with the given data
 * @throws NullPointerException if json is null
 * @throws JsonParseException   if the data is not valid or could not be read for some reason
 */
public static ValidatedCardFactory fromReader(Reader reader) {
    if (reader == null) {
        throw new NullPointerException("json cannot be null");
    }

    CardTypeDefinition[] typeDefinitions = new Gson().fromJson(reader, CardTypeDefinition[].class);
    if (typeDefinitions == null) {
        throw new JsonParseException("reader is at EOF");
    }

    return fromParsedCardTypeDefinitions(typeDefinitions);
}

From source file:plasticfantastic.ValidatedCardFactory.java

License:Apache License

private static ValidatedCardFactory fromParsedCardTypeDefinitions(CardTypeDefinition[] typeDefinitions) {
    try {/*from   www .j  a  v  a2  s  .  c  o  m*/
        return fromCardTypeDefinitions(typeDefinitions);
    } catch (IllegalArgumentException e) {
        throw new JsonParseException(e);
    }
}

From source file:qa.qcri.nadeef.core.datamodel.RuleJsonAdapter.java

License:Open Source License

@Override
public CleanPlanJsonAdapter deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    Gson gson = new Gson();
    JsonObject rootObj = (JsonObject) jsonElement;
    DBConfigJsonAdapter dbConfigJson = gson.fromJson(rootObj.get("source"), DBConfigJsonAdapter.class);

    if (Strings.isNullOrEmpty(dbConfigJson.type))
        throw new JsonParseException("Data source type is missing.");

    if (dbConfigJson.type.equalsIgnoreCase("csv")
            && (dbConfigJson.file == null || dbConfigJson.file.size() == 0))
        throw new JsonParseException("File path is missing.");

    if ((!dbConfigJson.isCSV())
            && (Strings.isNullOrEmpty(dbConfigJson.url) || Strings.isNullOrEmpty(dbConfigJson.username)))
        throw new JsonParseException("Database source is not correct.");

    List<RuleJsonAdapter> ruleJson = gson.fromJson(rootObj.get("rule"), new TypeToken<List<RuleJsonAdapter>>() {
    }.getType());//from www.j a  v  a 2s .  co m

    if (ruleJson == null || ruleJson.size() == 0)
        throw new JsonParseException("Rule cannot be empty.");
    for (RuleJsonAdapter rule : ruleJson) {
        if (Strings.isNullOrEmpty(rule.type) || (rule.hasTable() && rule.table.size() > 2) || rule.value == null
                || rule.value.size() == 0)
            throw new JsonParseException("Rule is not correct.");

        if (dbConfigJson.isCSV()) {
            // check the table name correctness
            List<String> fullFileNames = Lists.newArrayList();
            for (String fullFileName : dbConfigJson.file)
                fullFileNames.add(Files.getNameWithoutExtension(fullFileName));
            if (rule.hasTable()) {
                for (String file : rule.table)
                    if (!fullFileNames.contains(file))
                        throw new JsonParseException("Invalid table name " + file + ".");
            }
        }

        if (rule.hasTarget() && rule.table.size() != rule.target.size())
            throw new JsonParseException("Table and Target tables do not have the same size.");
        if (rule.hasTable() && rule.table.size() > 2)
            throw new JsonParseException("Rule cannot work with more than 2 tables.");
    }

    return new CleanPlanJsonAdapter(dbConfigJson, ruleJson);
}

From source file:rest.ws.gson.deserializer.entity.CreateEntityDeserializer.java

@Override
public T deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException {
    try {/*from ww w .  j a  va 2s  .  c  om*/
        return clazz.newInstance();
    } catch (InstantiationException | IllegalAccessException ex) {
        throw new JsonParseException(ex);
    }
}