Example usage for com.fasterxml.jackson.databind JsonNode toString

List of usage examples for com.fasterxml.jackson.databind JsonNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode toString.

Prototype

public abstract String toString();

Source Link

Usage

From source file:controllers.GenerateDocumentsController.java

public static Result submitLp2() {
    JsonNode request = request().body().asJson();

    String[] result = new Gson().fromJson(request.toString(), new TypeToken<String[]>() {
    }.getType());//w w  w  . j a v a 2  s . c om

    session("lp2_company_name", result[0].toString());
    session("lp2_job_name", result[1].toString());
    session("lp2_attach_cv", result[2].toString());
    session("lp2_attach_portfolio", result[3]);
    session("lp2_attach_lr", result[4]);
    session("lp2_attach_certificates", result[5]);

    return ok();
}

From source file:org.kiji.rest.representations.KijiRestEntityId.java

/**
 * Create a list of KijiRestEntityIds from a string input, which can be a json array of valid
 * entity id strings and/or valid hbase row keys.
 * This method is used for entity ids specified from the URL.
 *
 * @param entityIdListString string of a json array of rows identifiers.
 * @param layout of the table in which the entity id belongs.
 *        If null, then long components may not be recognized.
 * @return a properly constructed list of KijiRestEntityIds.
 * @throws IOException if KijiRestEntityId list can not be properly constructed.
 *//*from  w w w .j  av a 2s . c  o m*/
public static List<KijiRestEntityId> createListFromUrl(final String entityIdListString,
        final KijiTableLayout layout) throws IOException {
    final JsonParser parser = new JsonFactory().createJsonParser(entityIdListString)
            .enable(Feature.ALLOW_COMMENTS).enable(Feature.ALLOW_SINGLE_QUOTES)
            .enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES);
    final JsonNode jsonNode = BASIC_MAPPER.readTree(parser);

    List<KijiRestEntityId> kijiRestEntityIds = Lists.newArrayList();

    if (jsonNode.isArray()) {
        for (JsonNode node : jsonNode) {
            if (node.isTextual()) {
                kijiRestEntityIds.add(createFromUrl(node.textValue(), layout));
            } else {
                kijiRestEntityIds.add(createFromUrl(node.toString(), layout));
            }
        }
    } else {
        throw new IOException("The entity id list string is not a valid json array.");
    }

    return kijiRestEntityIds;
}

From source file:controllers.GenerateDocumentsController.java

public static Result submitLp3() {
    User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email"));

    JsonNode request = request().body().asJson();

    if (user != null) {
        String[][] skills = new Gson().fromJson(request.toString(), new TypeToken<String[][]>() {
        }.getType());/*ww  w  .  j av  a2s . c o  m*/
        if (user.skill.isEmpty()) {
            for (int i = 0; i < skills.length; i++) {
                user.skill.add(i, new Skill(skills[i][0], skills[i][1]));
            }
        } else {
            for (int i = 0; i < skills.length; i++) {
                user.skill.get(i).level = skills[i][1];
            }
        }
        user.completedOrientationSteps.skills = String.valueOf(true);
        SingletonDataSource.getInstance().updateAllUserData(user);
    }
    return redirect("/orientation");
}

From source file:controllers.oer.Application.java

private static Pair<String, Lang> negotiateContent(JsonNode json) {
    for (MediaRange mediaRange : request().acceptedTypes())
        for (Serialization serialization : Serialization.values())
            for (String mimeType : serialization.getTypes())
                if (mediaRange.accepts(mimeType)) {
                    if (serialization.format.equals(Lang.JSONLD))
                        return Pair.of(withRemoteContext(json.toString()), Lang.JSONLD);
                    Logger.debug("Matching mime {}, converting JSON to {}", mimeType, serialization.format);
                    return Pair.of(NtToEs.jsonLdToRdf(json, serialization.format), serialization.format);
                }// ww w  .  j  ava  2s . c  o  m
    return null;
}

From source file:com.baasbox.service.scripting.ScriptingService.java

private static ODocument updateStorageLocked(String name, boolean before, JsonCallback updaterFn)
        throws ScriptException {
    final ScriptsDao dao = ScriptsDao.getInstance();
    ODocument script = null;/*  ww  w .j  a va 2  s .  c  o  m*/
    try {
        script = dao.getByNameLocked(name);
        if (script == null)
            throw new ScriptException("Script not found");
        ODocument retScript = before ? script.copy() : script;

        ODocument storage = script.<ODocument>field(ScriptsDao.LOCAL_STORAGE);

        Optional<ODocument> storage1 = Optional.ofNullable(storage);

        JsonNode current = storage1.map(ODocument::toJSON).map(Json.mapper()::readTreeOrMissing)
                .orElse(NullNode.getInstance());
        if (current.isMissingNode())
            throw new ScriptEvalException("Error reading local storage as json");

        JsonNode updated = updaterFn.call(current);
        ODocument result;
        if (updated == null || updated.isNull()) {
            script.removeField(ScriptsDao.LOCAL_STORAGE);
        } else {
            result = new ODocument().fromJSON(updated.toString());
            script.field(ScriptsDao.LOCAL_STORAGE, result);
        }
        dao.save(script);
        ODocument field = retScript.field(ScriptsDao.LOCAL_STORAGE);
        return field;
    } finally {
        if (script != null) {
            script.unlock();
        }
    }
}

From source file:com.baasbox.service.push.providers.APNServer.java

public static boolean validatePushPayload(JsonNode bodyJson) throws BaasBoxPushException {
    JsonNode soundNode = bodyJson.findValue("sound");

    JsonNode contentAvailableNode = bodyJson.findValue("content-available");
    Integer contentAvailable = null;
    if (!(contentAvailableNode == null)) {
        if (!(contentAvailableNode.isInt()))
            throw new PushContentAvailableFormatException(
                    "Content-available MUST be an Integer (1 for silent notification)");
        contentAvailable = contentAvailableNode.asInt();
    }/*from  www .ja v  a  2s.  c o  m*/

    if (contentAvailable != null && contentAvailable != 1) {

        JsonNode categoryNode = bodyJson.findValue("category");
        String category = null;
        if (!(categoryNode == null)) {
            if (!(categoryNode.isTextual()))
                throw new PushCategoryFormatException("Category MUST be a String");
            category = categoryNode.asText();
        }

        String sound = null;
        if (!(soundNode == null)) {
            if (!(soundNode.isTextual()))
                throw new PushSoundKeyFormatException("Sound value MUST be a String");
            sound = soundNode.asText();
        }

        JsonNode actionLocKeyNode = bodyJson.findValue("actionLocalizedKey");
        String actionLocKey = null;

        if (!(actionLocKeyNode == null)) {
            if (!(actionLocKeyNode.isTextual()))
                throw new PushActionLocalizedKeyFormatException("ActionLocalizedKey MUST be a String");
            actionLocKey = actionLocKeyNode.asText();
        }

        JsonNode locKeyNode = bodyJson.findValue("localizedKey");
        String locKey = null;

        if (!(locKeyNode == null)) {
            if (!(locKeyNode.isTextual()))
                throw new PushLocalizedKeyFormatException("LocalizedKey MUST be a String");
            locKey = locKeyNode.asText();
        }

        JsonNode locArgsNode = bodyJson.get("localizedArguments");

        List<String> locArgs = new ArrayList<String>();
        if (!(locArgsNode == null)) {
            if (!(locArgsNode.isArray()))
                throw new PushLocalizedArgumentsFormatException(
                        "LocalizedArguments MUST be an Array of String");
            for (JsonNode locArgNode : locArgsNode) {
                if (!locArgNode.isTextual())
                    throw new PushLocalizedArgumentsFormatException(
                            "LocalizedArguments MUST be an Array of String");
                locArgs.add(locArgNode.toString());
            }
        }

        JsonNode customDataNodes = bodyJson.get("custom");

        Map<String, JsonNode> customData = new HashMap<String, JsonNode>();

        if (!(customDataNodes == null)) {
            if (customDataNodes.isTextual()) {
                customData.put("custom", customDataNodes);
            } else {
                for (JsonNode customDataNode : customDataNodes) {
                    customData.put("custom", customDataNodes);
                }
            }
        }

        JsonNode badgeNode = bodyJson.findValue("badge");
        int badge = 0;
        if (!(badgeNode == null)) {
            if (!(badgeNode.isNumber()))
                throw new PushBadgeFormatException("Badge value MUST be a number");
            else
                badge = badgeNode.asInt();
        }
    }
    return true;
}

From source file:controllers.GenerateDocumentsController.java

public static Result addNoStudiesGenerate() {
    JsonNode request = request().body().asJson();
    User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email"));

    String[] studies = new Gson().fromJson(request.toString(), new TypeToken<String[]>() {
    }.getType());//from   www.j a  va2  s  .  c  o m

    user.studyTitle = studies[0];
    user.studyLocation = "";

    user.completedOrientationSteps.currentSituation = String.valueOf(true);
    SingletonDataSource.getInstance().updateAllUserData(user);

    return ok(Json.toJson(studies));

}

From source file:controllers.GenerateDocumentsController.java

public static Result addStudiesGenerate() {
    JsonNode request = request().body().asJson();
    User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email"));

    String[] studies = new Gson().fromJson(request.toString(), new TypeToken<String[]>() {
    }.getType());//from w w w . ja v  a 2 s  . co m

    user.studyTitle = studies[0];
    user.studyLocation = studies[1];

    user.completedOrientationSteps.currentSituation = String.valueOf(true);
    SingletonDataSource.getInstance().updateAllUserData(user);

    return ok(Json.toJson(studies));

}

From source file:controllers.GenerateDocumentsController.java

public static Result deleteExperienceCurrentSituation() {
    JsonNode request = request().body().asJson();
    User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email"));

    String idExperience = new Gson().fromJson(request.toString(), new TypeToken<String>() {
    }.getType());//  w w  w. ja v a 2  s .  c  om
    for (int i = 0; i < user.currentSituation.professionalExperienceList.size(); i++) {
        if (user.currentSituation.professionalExperienceList.get(i).ID.contains(idExperience)) {
            user.currentSituation.professionalExperienceList.remove(i);
            break;
        }
    }

    user.completedOrientationSteps.currentSituation = String.valueOf(true);
    SingletonDataSource.getInstance().updateAllUserData(user);

    return ok(Json.toJson(idExperience));

}

From source file:com.baasbox.service.storage.DocumentService.java

/**
 * /* www  .jav a2  s. com*/
 * @param collectionName
 * @param rid
 * @param bodyJson
 * @return the updated document, null if the document is not found or belongs to another collection
 * @throws InvalidCollectionException
 * @throws DocumentNotFoundException 
 * @throws IllegalArgumentException 
 * @throws ODatabaseException 
 * @throws UpdateOldVersionException 
 */
public static ODocument update(String collectionName, String rid, JsonNode bodyJson)
        throws InvalidCollectionException, InvalidModelException, ODatabaseException, IllegalArgumentException,
        DocumentNotFoundException, UpdateOldVersionException {
    ODocument doc = get(collectionName, rid);
    if (doc == null)
        throw new InvalidParameterException(rid + " is not a valid document");
    //update the document
    DocumentDao dao = DocumentDao.getInstance(collectionName);
    dao.update(doc, (ODocument) (new ODocument()).fromJSON(bodyJson.toString()));

    return doc;//.toJSON("fetchPlan:*:0 _audit:1,rid");
}