List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:com.marklogic.xcc.ContentFactory.java
/** * Create a new {@link Content} object from a Jackson {@link Node} object. * /*from w w w .java2s .co m*/ * @param uri * The URI (name) with which the document will be inserted into the content store. If * the URI already exists in the store, it will be replaced with the new content. If * not explicitly overridden, the document format will be set to JSON. * @param documentNode * A Jackson {@link Node} object which is the content. Only Nodes of type Array or * Object are valid. * @param createOptions * Creation meta-information to be applied when the content is inserted into the * contentbase. These options control the document format (json, xml, text, binary) and * access permissions. * @return A {@link Content} object suitable for passing to * {@link Session#insertContent(Content)} */ public static Content newJsonContent(String uri, JsonNode documentNode, ContentCreateOptions createOptions) { return newContent(uri, bytesFromString(documentNode.toString()), (createOptions == null) ? ContentCreateOptions.newJsonInstance() : createOptions); }
From source file:com.cedarsoft.serialization.test.utils.AbstractJsonSerializerTest2.java
@Nonnull public static String addTypeInformation(@Nonnull String type, @Nonnull Version version, @Nonnull byte[] xmlBytes) throws Exception { JsonNode tree = new ObjectMapper().readTree(new String(xmlBytes, Charsets.UTF_8)); Map<String, JsonNode> newProps = new LinkedHashMap<String, JsonNode>(); newProps.put("@type", new TextNode(type)); newProps.put("@version", new TextNode(version.format())); Iterator<Map.Entry<String, JsonNode>> nodeIterator = tree.fields(); while (nodeIterator.hasNext()) { Map.Entry<String, JsonNode> jsonNode = nodeIterator.next(); newProps.put(jsonNode.getKey(), jsonNode.getValue()); }//from w ww.j a v a 2 s . c o m ((ContainerNode) tree).removeAll(); ((ObjectNode) tree).putAll(newProps); return tree.toString(); }
From source file:controllers.GenerateDocumentsController.java
public static Result submitCv2() { JsonNode request = request().body().asJson(); User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email")); if (user != null) { String[] result = new Gson().fromJson(request.toString(), new TypeToken<String[]>() { }.getType());/*from w w w .j a v a 2 s .co m*/ user.educationLevel = result[0]; if (result[1].equals("EmptyExperience")) { user.currentSituation.professionalExperienceList = new ArrayList<>(); } else { String[][] professionalExperience = new Gson().fromJson(result[1], new TypeToken<String[][]>() { }.getType()); List<ProfessionalExperience> auxProfessionalExperience = new ArrayList<>(); for (int i = 0; i < professionalExperience.length; i++) { String expID = UUID.randomUUID().toString(); auxProfessionalExperience.add( new ProfessionalExperience(professionalExperience[i][0], professionalExperience[i][1], professionalExperience[i][2], professionalExperience[i][3], expID)); } user.currentSituation.professionalExperienceList = auxProfessionalExperience; } List<String> interests = new Gson().fromJson(result[2].toString(), new TypeToken<List<String>>() { }.getType()); user.interests = interests; SingletonDataSource.getInstance().updateAllUserData(user); } return redirect("/orientation/gettools/cv3"); }
From source file:controllers.GenerateDocumentsController.java
public static Result submitCv3() { JsonNode request = request().body().asJson(); User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email")); if (user != null) { String[] result = new Gson().fromJson(request.toString(), new TypeToken<String[]>() { }.getType());//from w w w .ja va 2s. c o m String[][] courses = new Gson().fromJson(result[0], new TypeToken<String[][]>() { }.getType()); if (courses.length > 0) { List<Course> auxCourses = new ArrayList<>(); for (int i = 0; i < courses.length; i++) { auxCourses.add(new Course(courses[i][0], courses[i][1], courses[i][2])); } user.courses = auxCourses; } String[][] languages = new Gson().fromJson(result[1], new TypeToken<String[][]>() { }.getType()); if (languages.length > 0) { List<Language> auxLanguages = new ArrayList<>(); for (int i = 0; i < languages.length; i++) { auxLanguages.add(new Language(languages[i][0], languages[i][1])); } user.languages = auxLanguages; } String[][] software = new Gson().fromJson(result[2], new TypeToken<String[][]>() { }.getType()); if (software.length > 0) { List<Software> auxSoftware = new ArrayList<>(); for (int i = 0; i < software.length; i++) { auxSoftware.add(new Software(software[i][0], software[i][1])); } user.softwareList = auxSoftware; } SingletonDataSource.getInstance().updateAllUserData(user); } return redirect("/orientation/gettools/cv4"); }
From source file:controllers.GenerateDocumentsController.java
public static Result submitCv1() { JsonNode request = request().body().asJson(); User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email")); if (user != null) { String[] personalInformation = new Gson().fromJson(request.toString(), new TypeToken<String[]>() { }.getType());/* w ww . j av a 2 s. c om*/ //user.name = personalInformation[0]; //user.surnames = personalInformation[1]; user.birthDate = Utils.changeFormatDate(personalInformation[2]); user.residenceCity = personalInformation[3]; user.residenceAddress = personalInformation[4]; user.residenceNumber = personalInformation[5]; user.residenceZipCode = personalInformation[6]; //user.email = personalInformation[7]; user.phoneNumber = personalInformation[8]; if (!personalInformation[9].equals("")) { //Add driving license user.drivingLicense = personalInformation[9]; } else { user.drivingLicense = null; } if (!personalInformation[10].equals("")) { user.certificateOfDisability = personalInformation[10]; } else { user.certificateOfDisability = null; } SingletonDataSource.getInstance().updateAllUserData(user); } return redirect("/orientation/gettools/cv2"); }
From source file:controllers.GenerateDocumentsController.java
public static Result submitLp1() { JsonNode request = request().body().asJson(); User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email")); if (user != null) { String[] personalInformation = new Gson().fromJson(request.toString(), new TypeToken<String[]>() { }.getType());//www .j a v a2 s. c om //user.name = personalInformation[0]; //user.surnames = personalInformation[1]; user.birthDate = personalInformation[2]; user.residenceCity = personalInformation[3]; user.residenceAddress = personalInformation[4]; user.residenceNumber = personalInformation[5]; user.residenceZipCode = personalInformation[6]; //user.email = personalInformation[7]; user.phoneNumber = personalInformation[8]; if (!personalInformation[9].equals("")) { //Add academic experience String[] academicExp = new Gson().fromJson(personalInformation[9].toString(), new TypeToken<String[]>() { }.getType()); user.studyTitle = academicExp[0]; user.studyLocation = academicExp[1]; } else { user.studyTitle = null; user.studyLocation = null; } List<String> personalCharacteristics = new Gson().fromJson(personalInformation[10].toString(), new TypeToken<List<String>>() { }.getType()); user.personalCharacteristics = personalCharacteristics; SingletonDataSource.getInstance().updateAllUserData(user); } return redirect("/orientation/gettools/lp2"); }
From source file:org.apache.usergrid.java.client.utils.JsonUtils.java
@Nullable @SuppressWarnings("unchecked") public static <T> T getProperty(@NotNull final Map<String, JsonNode> properties, @NotNull final String name) { JsonNode value = properties.get(name); if (value == null) { return null; } else if (value instanceof TextNode) { return (T) value.asText(); } else if (value instanceof LongNode) { Long valueLong = value.asLong(); return (T) valueLong; } else if (value instanceof BooleanNode) { Boolean valueBoolean = value.asBoolean(); return (T) valueBoolean; } else if (value instanceof IntNode) { Integer valueInteger = value.asInt(); return (T) valueInteger; } else if (value instanceof FloatNode) { return (T) Float.valueOf(value.toString()); } else {// ww w . ja v a 2s . c om return (T) value; } }
From source file:com.baasbox.service.scripting.ScriptingService.java
private static JsonNode callJsonSync(String url, String method, Map<String, List<String>> params, Map<String, List<String>> headers, JsonNode body, Integer timeout) throws Exception { try {/*ww w . j av a2 s . c o m*/ ObjectNode node = Json.mapper().createObjectNode(); WS.Response resp = null; long startTime = System.nanoTime(); if (timeout == null) { resp = HttpClientService.callSync(url, method, params, headers, body == null ? null : (body.isValueNode() ? body.toString() : body)); } else { resp = HttpClientService.callSync(url, method, params, headers, body == null ? null : (body.isValueNode() ? body.toString() : body), timeout); } long endTime = System.nanoTime(); int status = resp.getStatus(); node.put("status", status); node.put("execution_time", (endTime - startTime) / 1000000L); String header = resp.getHeader("Content-Type"); if (header == null || header.startsWith("text")) { node.put("body", resp.getBody()); } else if (header.startsWith("application/json")) { node.put("body", resp.asJson()); } else { node.put("body", resp.getBody()); } return node; } catch (Exception e) { BaasBoxLogger.error("failed to connect: " + ExceptionUtils.getMessage(e)); throw e; } }
From source file:controllers.GenerateDocumentsController.java
public static Result addExperienceGenerate() { JsonNode request = request().body().asJson(); User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email")); if (user == null) { return redirect("/"); }//from w w w . j a va 2 s .c o m String[] experience = new Gson().fromJson(request.toString(), new TypeToken<String[]>() { }.getType()); List<ProfessionalExperience> currentExperienceCopy = new ArrayList<ProfessionalExperience>(); //for(int j=0; j<user.currentSituation.professionalExperienceList.size();j++){ if (user.currentSituation.professionalExperienceList.size() == 0) { String experienceID; String expID = UUID.randomUUID().toString(); user.currentSituation.addProfessionalExperience(experience[0], experience[1], experience[2], experience[3], expID); } else { // Copiamos el array de experiencia profesional for (ProfessionalExperience professionalExperience : user.currentSituation.professionalExperienceList) { currentExperienceCopy.add(professionalExperience); } int addNewElement = 1; for (ProfessionalExperience professionalExperience : currentExperienceCopy) { if (professionalExperience.company.toLowerCase().equals(experience[0].toLowerCase()) && professionalExperience.job.toLowerCase().equals(experience[1].toLowerCase()) /*&& professionalExperience.experienceYears.equals(experience[i][2])*/) { //Logger.debug("Salgo del for porque ya existe"); addNewElement = 0; break; } } if (addNewElement == 1) { for (ProfessionalExperience professionalExperience : currentExperienceCopy) { if (professionalExperience.company.equals("No tengo experiencia")) { // Logger.debug("Borro"); user.currentSituation.clearProfessionalExperience(); } } String expID = UUID.randomUUID().toString(); // Logger.debug("Aado la nueva experiencia"); user.currentSituation.addProfessionalExperience(experience[0], experience[1], experience[2], experience[3], expID); } } user.completedOrientationSteps.currentSituation = String.valueOf(true); SingletonDataSource.getInstance().updateAllUserData(user); return ok(Json.toJson(experience)); }
From source file:controllers.GenerateDocumentsController.java
public static Result addCheckExperienceGenerate() { JsonNode request = request().body().asJson(); User user = SingletonDataSource.getInstance().getUserByEmail(session().get("email")); if (user == null) { return redirect("/orientation/gettools/cv2"); }/*from ww w. j ava 2 s.c o m*/ String checkExperience = new Gson().fromJson(request.toString(), new TypeToken<String>() { }.getType()); if (user.currentSituation.professionalExperienceList.size() == 0) { String expID = UUID.randomUUID().toString(); user.currentSituation.addProfessionalExperience(checkExperience, "", "", "", expID); } else { for (int i = 0; i < user.currentSituation.professionalExperienceList.size(); i++) { if (user.currentSituation.professionalExperienceList.get(i).company .equals("No tengo experiencia")) { //Logger.info("La Base de datos contiene el check de no tengo experiencia"); } else { //Logger.info("La Base de datos no contiene el check de no tengo experiencia"); user.currentSituation.clearProfessionalExperience(); String expID = UUID.randomUUID().toString(); user.currentSituation.addProfessionalExperience(checkExperience, "", "", "", expID); } } } user.completedOrientationSteps.currentSituation = String.valueOf(true); SingletonDataSource.getInstance().updateAllUserData(user); return ok(Json.toJson(checkExperience)); }