Example usage for com.google.gson JsonParser JsonParser

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

Introduction

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

Prototype

@Deprecated
public JsonParser() 

Source Link

Usage

From source file:ai.nitro.bot4j.integration.slack.receive.webhook.impl.SlackActionWebhookImpl.java

License:Open Source License

@Override
public String post(final HttpServletRequest req, final HttpServletResponse res) {
    try {/*from ww w  . j a  va 2 s . c om*/
        final String payload = req.getParameter("payload");
        final JsonParser jsonParser = new JsonParser();
        final JsonObject json = jsonParser.parse(payload).getAsJsonObject();

        slackReceiveHandler.handleAction(json, (long) 0);
    } catch (final Exception e) {
        handleException(e);
    }

    return "";
}

From source file:ai.nitro.bot4j.integration.slack.receive.webhook.impl.SlackEventWebhookImpl.java

License:Open Source License

@Override
public String post(final HttpServletRequest req, final HttpServletResponse res) {
    String result = "";

    try {/*from  w w  w . j a va2  s.c  o m*/
        final String body = CharStreams.toString(req.getReader());
        final JsonParser jsonParser = new JsonParser();
        final JsonObject jsonReq = jsonParser.parse(body).getAsJsonObject();

        if (!jsonReq.has(TYPE)) {
            LOG.warn("no type in JSON");
        } else {
            final JsonElement typeJsonElement = jsonReq.get(TYPE);
            final String type = typeJsonElement.getAsString();

            switch (type) {
            case URL_VERIFICATION:
                result = handleUrlVerification(jsonReq, res);
                break;
            case EVENT_CALLBACK:
                handleEvent(jsonReq, res);
                break;
            default:
                LOG.info("unknown type {}", type);
                break;
            }
        }
    } catch (final Exception e) {
        handleException(e);
    }

    return result;
}

From source file:algorithmi.models.Categories.java

public Categories(String data) {
    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject Categories = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(Categories.entrySet());
    /**//  w  w  w .j av a2  s  .  co  m
     *
     * Revalidar TUDO, formatos, campos vazios, TUDO!!
     *
     */
    validateData();
    //Associa os dados ao objecto Question
    this._id = Categories.get("_id").getAsInt(); //ir buscar o max id da bd + 1 
    this.description = Categories.get("description").getAsString();

}

From source file:algorithmi.models.CodeLang.java

public CodeLang(String data) {
    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject CodeLang = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(CodeLang.entrySet());
    /**// w  ww  .ja  va 2 s.c  o  m
     *
     * Revalidar TUDO, formatos, campos vazios, TUDO!!
     *
     */
    validateData();
    //Associa os dados ao objecto Question
    this.questionID = CodeLang.get("questionID").getAsInt(); //ir buscar o max id da bd + 1 
    this.highLevelLandID = CodeLang.get("highLevelLandID").getAsInt();
    this.programCode = CodeLang.get("programCode").getAsString();

}

From source file:algorithmi.models.Course.java

License:Apache License

public Course(String data) {

    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject Course = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(Course.entrySet());
    /**/*  w ww. j a  va 2s.c  om*/
     *
     * Revalidar TUDO, formatos, campos vazios, TUDO!!
     *
     */
    validateData();
    //Associa os dados ao objecto Course
    this.codCourse = Course.getAsInt(); //ir buscar o max id da bd + 1 
    this.name = Course.get("name").getAsString();
    this.school = Course.get("school").getAsInt();

}

From source file:algorithmi.models.Details.java

public Details(String data) {

    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject details = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(details.entrySet());
    //Revalidar TUDO, formatos, campos vazios, TUDO!!
    validateData();/*from   w  w  w  . ja  v a 2s  .c o m*/

    this.matrixTestID = details.get("matrixTestID").getAsInt();
    this.categoryID = details.get("categoryID").getAsInt();
    this.numberOfQuestions = details.get("numberOfQuestions").getAsInt();
}

From source file:algorithmi.models.HighLevelLangs.java

public HighLevelLangs(String data) {
    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject HighLevelLangs = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(HighLevelLangs.entrySet());
    /**//from w  w w . ja  v a2s.c  o m
     *
     * Revalidar TUDO, formatos, campos vazios, TUDO!!
     *
     */
    validateData();
    //Associa os dados ao objecto Question
    this._id = HighLevelLangs.get("_id").getAsInt(); //ir buscar o max id da bd + 1 
    this.description = HighLevelLangs.get("description").getAsString();

}

From source file:algorithmi.models.Institutions.java

public Institutions(String data) {

    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject institutions = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(institutions.entrySet());
    //Revalidar TUDO, formatos, campos vazios, TUDO!!
    validateData();//from  w ww. ja v a 2 s.c  om

    //TEM DE IR BUSCAR O ULTIMO ID E ACRESCENTAR UM
    this._id = 123;
    this.name = institutions.get("name").getAsString();
    this.address = institutions.get("address").getAsString();
}

From source file:algorithmi.Models.Question.java

License:Apache License

public Question(String data) {
    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject Question = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(Question.entrySet());
    /**/* w w  w .j ava 2  s  .  c o  m*/
     *
     * Revalidar TUDO, formatos, campos vazios, TUDO!!
     *
     */
    validateData();
    //Associa os dados ao objecto Question
    this._id = 123; //ir buscar o max id da bd + 1 
    this.title = Question.get("titulo").getAsString();
    this.category = Question.get("categoria").getAsInt();
    this.description = Question.get("descricao").getAsString();
    this.image = Question.get("imagem").getAsString();
    this.algorithm = Question.get("algoritmo").getAsString();
}

From source file:algorithmi.models.QuestionIO.java

public QuestionIO(String data) {
    //Transforma a string recebida pelo pedido http para json
    JsonParser jsonParser = new JsonParser();
    JsonObject QuestionIO = (JsonObject) jsonParser.parse(data);
    //Exibe os dados, em formato json
    System.out.println(QuestionIO.entrySet());
    /**//from  w  ww  . j a  v a2s . c om
     *
     * Revalidar TUDO, formatos, campos vazios, TUDO!!
     *
     */
    validateData();
    //Associa os dados ao objecto Question
    this._id = 123; //ir buscar o max id da bd + 1 
    this.question = QuestionIO.get("titulo").getAsInt();
    this.in = QuestionIO.get("in").getAsString();
    this.out = QuestionIO.get("out").getAsString();

}