List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.networknt.light.rule.validation.AbstractValidationRule.java
public static JsonSchema getSchema(String ruleClass) throws Exception { JsonSchema schema = null;//from w ww . j a va2 s . co m Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) ruleMap.get("cache"); if (cache == null) { cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(1000).build(); ruleMap.put("cache", cache); } else { Map<String, Object> rule = (Map<String, Object>) cache.get(ruleClass); if (rule != null) { schema = (JsonSchema) rule.get("schema"); } } if (schema == null) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OIndex<?> validationRuleClassIdx = graph.getRawGraph().getMetadata().getIndexManager() .getIndex("Validation.ruleClass"); OIdentifiable oid = (OIdentifiable) validationRuleClassIdx.get(ruleClass); if (oid != null) { ODocument validation = (ODocument) oid.getRecord(); String json = validation.toJSON(); JsonNode validationNode = ServiceLocator.getInstance().getMapper().readTree(json); JsonNode schemaNode = validationNode.get("schema"); schema = factory.getJsonSchema(schemaNode); Map<String, Object> rule = (Map<String, Object>) cache.get(ruleClass); if (rule != null) { rule.put("schema", schema); } else { rule = new HashMap<String, Object>(); rule.put("schema", schema); cache.put(ruleClass, rule); } } else { // could not find the rule validation schema from db. put null in cache so that // the next operation won't check db again. Map<String, Object> rule = (Map<String, Object>) cache.get(ruleClass); if (rule != null) { rule.put("schema", null); } else { rule = new HashMap<String, Object>(); rule.put("schema", null); cache.put(ruleClass, rule); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } } return schema; }
From source file:io.github.robwin.swagger2markup.Swagger2MarkupConverter.java
/** * Creates a Swagger2MarkupConverter.Builder from a given Swagger YAML or JSON String. * * @param swagger the Swagger YAML or JSON String. * @return a Swagger2MarkupConverter// ww w. ja va 2 s .c o m * @throws java.io.IOException if String can not be parsed */ public static Builder fromString(String swagger) throws IOException { Validate.notEmpty(swagger, "swagger must not be null!"); ObjectMapper mapper; if (swagger.trim().startsWith("{")) { mapper = Json.mapper(); } else { mapper = Yaml.mapper(); } JsonNode rootNode = mapper.readTree(swagger); // must have swagger node set JsonNode swaggerNode = rootNode.get("swagger"); if (swaggerNode == null) throw new IllegalArgumentException("Swagger String is in the wrong format"); return new Builder(mapper.convertValue(rootNode, Swagger.class)); }
From source file:com.pkrete.locationservice.admin.util.LocationJSONDeserializerHelper.java
/** * Deserializes descriptions and notes variables. * * @param location Location object// w ww. j a va 2 s. co m * @param node JSON node that contains the data */ public static void deserializeDescriptionsAndNotes(Location location, JsonNode node) { // Get languagesService bean from Application Context LanguagesService languagesService = (LanguagesService) ApplicationContextUtils.getApplicationContext() .getBean("languagesService"); // Language cache Map<Integer, Language> languages = new HashMap<Integer, Language>(); List<Description> descriptions = new ArrayList<Description>(); // Does descriptions node exist if (node.path("descriptions") != null) { // Parse descriptions Iterator<JsonNode> ite = node.path("descriptions").elements(); // Iterate redirects while (ite.hasNext()) { // Get next description JsonNode temp = ite.next(); // Parse id int descId = temp.get("id") == null ? 0 : temp.get("id").intValue(); // Parse language id int languageId = temp.get("lang_id") == null ? 0 : temp.get("lang_id").intValue(); // Parse value String value = temp.get("value") == null ? "" : temp.get("value").textValue(); // Check if the language is cached if (!languages.containsKey(languageId)) { // Get language from DB and cache it languages.put(languageId, languagesService.getLanguageById(languageId)); } descriptions.add(new Description(descId, languages.get(languageId), value)); } } // Set descriptions location.setDescriptions(descriptions); List<Note> notes = new ArrayList<Note>(); // Does notes node exist if (node.path("notes") != null) { // Parse notes Iterator<JsonNode> ite = node.path("notes").elements(); // Iterate notes while (ite.hasNext()) { // Get next note JsonNode temp = ite.next(); // Parse id int noteId = temp.get("id") == null ? 0 : temp.get("id").intValue(); // Parse language id int languageId = temp.get("lang_id") == null ? 0 : temp.get("lang_id").intValue(); // Parse value String value = temp.get("value") == null ? "" : temp.get("value").textValue(); // Check if the language is cached if (!languages.containsKey(languageId)) { // Get language from DB and cache it languages.put(languageId, languagesService.getLanguageById(languageId)); } notes.add(new Note(noteId, languages.get(languageId), value)); } } // Set notes location.setNotes(notes); }
From source file:mobile.service.SelfInfoService.java
/** * ??,???Json// ww w.j a v a 2 s . c o m * * @param node ?Json * @return */ public static ServiceResult saveUserInfo(JsonNode node) { if (node.hasNonNull("language")) { String language = node.get("language").asText(); List<String> list = AttachmentApp.getLanguage(); if (!list.contains(language)) { return ServiceResults.illegalParameters("?language" + language); } } ObjectNodeResult result = Expert.saveExpertByJson(Context.current().session(), node); return ServiceResult.create(result); }
From source file:com.pkrete.locationservice.admin.util.LocationJSONDeserializerHelper.java
/** * Deserializes name, locationCode, floor, staffNote1, staffNote2, map and * image variables./*from ww w . ja v a2 s . co m*/ * * @param location Location object * @param node JSON node that contains the data */ public static void deserializeBasicGroup1(Location location, JsonNode node) { //int id = node.get("id") == null ? 0 : node.get("id").intValue(); String name = node.get("name") == null ? "" : node.get("name").textValue(); String locationCode = node.get("location_code") == null ? "" : node.get("location_code").textValue(); String floor = node.get("floor") == null ? "" : node.get("floor").textValue(); String staffNote1 = node.get("staff_note_1") == null ? "" : node.get("staff_note_1").textValue(); String staffNote2 = node.get("staff_note_2") == null ? "" : node.get("staff_note_2").textValue(); int imageId = node.get("image_id") == null ? 0 : node.get("image_id").intValue(); int mapId = node.get("map_id") == null ? 0 : node.get("map_id").intValue(); // Set values that have been parsed location.setName(name); location.setLocationCode(locationCode); location.setLocationId(0); location.setFloor(floor); location.setStaffNotePri(staffNote1); location.setStaffNoteSec(staffNote2); // Get imagesService bean from Application Context ImagesService imagesService = (ImagesService) ApplicationContextUtils.getApplicationContext() .getBean("imagesService"); // Get mapsService bean from Application Context MapsService mapsService = (MapsService) ApplicationContextUtils.getApplicationContext() .getBean("mapsService"); // Get Image object Image image = imagesService.get(imageId); // Get Map object com.pkrete.locationservice.admin.model.illustration.Map map = mapsService.get(mapId); // Set image and map location.setImage(image); location.setMap(map); }
From source file:com.github.fge.jsonschema2avro.predicates.AvroPredicates.java
public static Predicate<AvroPayload> array() { return new Predicate<AvroPayload>() { @Override/*from w w w . ja v a 2s .c om*/ public boolean apply(final AvroPayload input) { final JsonNode node = schemaNode(input); final NodeType type = getType(node); if (NodeType.ARRAY != type) return false; final JsonNode digest = ArraySchemaDigester.getInstance().digest(node); // FIXME: I should probably make digests POJOs here return digest.get("hasItems").booleanValue() ? !digest.get("itemsIsArray").booleanValue() : digest.get("hasAdditional").booleanValue(); } }; }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java
private static boolean isFridaySaturdayNight(JsonNode jsonNode, int hour) { boolean ret = false; try {//from w ww. j a v a 2 s. co m String nightString = jsonNode.get("departure").get(0).get("night").asText(); int startHour = Integer.parseInt((nightString.split(" ")[0]).split("\\.")[0]); int endHour = Integer.parseInt( (jsonNode.get("departure").get(0).get("night").asText().split(" ")[1]).split("\\.")[0]); if (hour >= startHour || hour < endHour) ret = true; } catch (Exception e) { LOG.e(e.getLocalizedMessage()); } return ret; }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.LocalTrainData.java
public static boolean hasLine(String line, Context context) { String lineNumber = line.split(" ")[0]; String jsonStr = Util.stringFromJsonAssets(context, "stations/local-trains-timetable.json"); JsonNode root = Util.stringToJsonNode(jsonStr); JsonNode lines = root.get("local-trains"); for (int i = 0; i < lines.size(); i++) { if (lines.get(i).get("line").asText().trim().equalsIgnoreCase(lineNumber.trim())) return true; }//from ww w .ja va 2 s .com return false; }
From source file:nl.esciencecenter.xnatclient.data.XnatParser.java
/** * Xnat Rest Query has a diferrent Json Tree. Parse structure * //ww w . ja v a2 s . c o m * @throws XnatParseException */ public static int parseJsonQueryResult(XnatObjectType type, String jsonStr, List list) throws XnatParseException { if (StringUtil.isEmpty(jsonStr)) return 0; try { JsonFactory jsonFac = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(); // use dom like parsing: JsonNode tree = mapper.readTree(jsonStr); JsonNode items = tree.get("items"); if (items == null) { logger.warnPrintf("Couldn't find 'items' in jsonTree\n"); return 0; } // parse objects: JsonNode node = null; Iterator<JsonNode> els = items.elements(); int index = 0; while (els.hasNext()) { logger.debugPrintf(" - item[%d]\n", index++); JsonNode el = els.next(); node = el.get("data_fields"); if (node != null) list.add(parseXnatObject(type, node)); else logger.warnPrintf("jsonNode doesn't have 'data_fields' element:%s", el); } } // wrap exception: catch (JsonParseException e) { throw new XnatParseException("JsonParseException:" + e.getMessage(), e); } catch (IOException e) { throw new XnatParseException("IOException:" + e.getMessage(), e); } return list.size(); }
From source file:org.jetbrains.webdemo.examples.ExamplesLoader.java
private static ExampleFile loadExampleFile(String path, String projectUrl, JsonNode fileManifest) throws IOException { try {/* w w w . ja v a 2 s . c o m*/ String fileName = fileManifest.get("filename").textValue(); boolean modifiable = fileManifest.get("modifiable").asBoolean(); boolean hidden = fileManifest.has("hidden") ? fileManifest.get("hidden").asBoolean() : false; String confType = fileManifest.has("confType") ? fileManifest.get("confType").asText() : null; File file = new File(path); String fileContent = new String(Files.readAllBytes(file.toPath())).replaceAll("\r\n", "\n"); String filePublicId = (projectUrl + "/" + fileName).replaceAll(" ", "%20"); ProjectFile.Type fileType = null; if (!fileManifest.has("type")) { fileType = ProjectFile.Type.KOTLIN_FILE; } else if (fileManifest.get("type").asText().equals("kotlin-test")) { fileType = ProjectFile.Type.KOTLIN_TEST_FILE; } else if (fileManifest.get("type").asText().equals("solution")) { fileType = ProjectFile.Type.SOLUTION_FILE; } else if (fileManifest.get("type").asText().equals("java")) { fileType = ProjectFile.Type.JAVA_FILE; } return new ExampleFile(fileName, fileContent, filePublicId, fileType, confType, modifiable, hidden); } catch (IOException e) { System.err.println("Can't load file: " + e.toString()); return null; } }