List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:models.metadata.ClimateService.java
public static List<ClimateService> getMostRecentlyAdded() { List<ClimateService> climateServices = new ArrayList<ClimateService>(); JsonNode climateServicesNode = APICall.callAPI(GET_MOST_RECENTLY_ADDED_CLIMATE_SERVICES_CALL); if (climateServicesNode == null || climateServicesNode.has("error") || !climateServicesNode.isArray()) { return climateServices; }/*from w w w . j ava2 s.co m*/ for (int i = 0; i < climateServicesNode.size(); i++) { JsonNode json = climateServicesNode.path(i); ClimateService newService = new ClimateService(); newService.setId(json.get("id").asText()); newService.setClimateServiceName(json.get("name").asText()); newService.setPurpose(json.findPath("purpose").asText()); newService.setUrl(json.findPath("url").asText()); newService.setScenario(json.findPath("scenario").asText()); newService.setVersion(json.findPath("versionNo").asText()); newService.setRootservice(json.findPath("rootServiceId").asText()); climateServices.add(newService); } return climateServices; }
From source file:com.flipkart.zjsonpatch.JsonDiff.java
private static Integer addRemaining(List<Diff> diffs, List<Object> path, JsonNode target, int pos, int targetIdx, int targetSize) { while (targetIdx < targetSize) { JsonNode jsonNode = target.get(targetIdx); List<Object> currPath = getPath(path, pos); diffs.add(Diff.generateDiff(Operation.ADD, currPath, jsonNode.deepCopy())); pos++;/*w w w . j a va2s . co m*/ targetIdx++; } return pos; }
From source file:models.metadata.ClimateService.java
public static List<ClimateService> getMostRecentlyUsed() { List<ClimateService> climateServices = new ArrayList<ClimateService>(); JsonNode climateServicesNode = APICall.callAPI(GET_MOST_RECENTLY_USED_CLIMATE_SERVICES_CALL); if (climateServicesNode == null || climateServicesNode.has("error") || !climateServicesNode.isArray()) { return climateServices; }//from w w w .j ava2 s . c om for (int i = 0; i < climateServicesNode.size(); i++) { JsonNode json = climateServicesNode.path(i); ClimateService newService = new ClimateService(); newService.setId(json.get("id").asText()); newService.setClimateServiceName(json.get("name").asText()); newService.setPurpose(json.findPath("purpose").asText()); newService.setUrl(json.findPath("url").asText()); newService.setScenario(json.findPath("scenario").asText()); newService.setVersion(json.findPath("versionNo").asText()); newService.setRootservice(json.findPath("rootServiceId").asText()); climateServices.add(newService); } return climateServices; }
From source file:models.metadata.ClimateService.java
public static List<ClimateService> getMostPopular() { List<ClimateService> climateServices = new ArrayList<ClimateService>(); JsonNode climateServicesNode = APICall.callAPI(GET_MOST_POPULAR_CLIMATE_SERVICES_CALL); if (climateServicesNode == null || climateServicesNode.has("error") || !climateServicesNode.isArray()) { return climateServices; }//from www . j ava2s . com for (int i = 0; i < climateServicesNode.size(); i++) { JsonNode json = climateServicesNode.path(i); ClimateService newService = new ClimateService(); newService.setId(json.get("id").asText()); newService.setClimateServiceName(json.get("name").asText()); newService.setPurpose(json.findPath("purpose").asText()); newService.setUrl(json.findPath("url").asText()); newService.setScenario(json.findPath("scenario").asText()); newService.setVersion(json.findPath("versionNo").asText()); newService.setRootservice(json.findPath("rootServiceId").asText()); climateServices.add(newService); } return climateServices; }
From source file:com.gsma.mobileconnect.utils.JsonUtils.java
/** * Query the parent node for the named child node. * * @param parentNode Node to check.//from ww w. ja v a2 s . c om * @param name Name of child node. * @return The child node if found. * @throws NoFieldException Thrown if field not found. */ static private JsonNode getExpectedNode(JsonNode parentNode, String name) throws NoFieldException { JsonNode childNode = parentNode.get(name); if (null == childNode) { throw new NoFieldException(name); } return childNode; }
From source file:com.gsma.mobileconnect.utils.JsonUtils.java
/** * Query the parent node for the named child node and return the text value of the child node * * @param parentNode Node to check.//w ww . j a va 2 s. co m * @param name Name of the child node. * @return The text value of the child node. * @throws NoFieldException Thrown if field not found. */ static private String getExpectedStringValue(JsonNode parentNode, String name) throws NoFieldException { JsonNode childNode = parentNode.get(name); if (null == childNode) { throw new NoFieldException(name); } return childNode.textValue(); }
From source file:io.orchestrate.client.ResponseConverterUtil.java
static <T> KvObject<T> wrapperJsonToKvObject(final ObjectMapper mapper, final JsonNode jsonNode, final Class<T> clazz) throws IOException { assert (mapper != null); assert (jsonNode != null); assert (clazz != null); // parse the PATH structure (e.g.): // {"collection":"coll","key":"aKey","ref":"someRef"} final JsonNode path = jsonNode.get("path"); if ("event".equals(path.get("kind").asText())) { return wrapperJsonToEvent(mapper, jsonNode, clazz); }/* w w w. j av a 2 s . c om*/ final String collection = path.get("collection").asText(); final String key = path.get("key").asText(); final String ref = path.get("ref").asText(); // parse result structure (e.g.): // {"path":{...},"value":{}} final JsonNode valueNode = jsonNode.get("value"); return jsonToKvObject(mapper, valueNode, clazz, collection, key, ref); }
From source file:dao.TrackingDAO.java
public static String addTrackingEvent(JsonNode requestNode, String user) { String message = "Internal error"; if (requestNode == null || (!requestNode.isContainerNode())) { return "Empty post body"; }//w w w. ja v a 2s.co m Long accessTime = 0L; if (requestNode.has(TRACKING_ACCESS_UNIX_TIME_COLUMN)) { accessTime = requestNode.get(TRACKING_ACCESS_UNIX_TIME_COLUMN).asLong(); } else { return "Missing " + TRACKING_ACCESS_UNIX_TIME_COLUMN; } String objectType = ""; if (requestNode.has(TRACKING_OBJECT_TYPE_COLUMN)) { objectType = requestNode.get(TRACKING_OBJECT_TYPE_COLUMN).asText(); } else { return "Missing " + TRACKING_OBJECT_TYPE_COLUMN; } Long objectId = 0L; if (requestNode.has(TRACKING_OBJECT_ID_COLUMN)) { objectId = requestNode.get(TRACKING_OBJECT_ID_COLUMN).asLong(); } else { return "Missing " + TRACKING_OBJECT_ID_COLUMN; } String objectName = ""; if (requestNode.has(TRACKING_OBJECT_NAME_COLUMN)) { objectName = requestNode.get(TRACKING_OBJECT_NAME_COLUMN).asText(); } else { return "Missing " + TRACKING_OBJECT_NAME_COLUMN; } String parameters = ""; if (requestNode.has(TRACKING_PARAMETERS_COLUMN)) { parameters = requestNode.get(TRACKING_PARAMETERS_COLUMN).asText(); } else { return "Missing " + TRACKING_PARAMETERS_COLUMN; } Integer userId = 0; if (StringUtils.isNotBlank(user)) { try { userId = (Integer) getJdbcTemplate().queryForObject(GET_USER_ID, Integer.class, user); } catch (EmptyResultDataAccessException e) { Logger.error("TrackingDAO addTrackingEvent get user id failed, username = " + user); Logger.error("Exception = " + e.getMessage()); } } if (userId != null && userId > 0) { try { int row = getJdbcTemplate().update(ADD_TRACKING_EVENT, accessTime, userId, objectType, objectId, objectName, parameters); if (row > 0) { message = ""; } } catch (Exception e) { message = e.getMessage(); } } else { message = "User not found"; } return message; }
From source file:models.DataSet.java
public static List<DataSet> all() { List<DataSet> dataSets = new ArrayList<DataSet>(); JsonNode dataSetNode = APICall.callAPI(GET_ALL_DATASET); if (dataSetNode == null || dataSetNode.has("error") || !dataSetNode.isArray()) { return dataSets; }//from w ww . ja va2 s . c o m for (int i = 0; i < dataSetNode.size(); i++) { JsonNode json = dataSetNode.path(i); DataSet dataset = new DataSet(); dataset.setId(json.get("id").asText()); dataset.setDataSetName(json.get("name").asText()); dataset.setAgencyId(json.get("agencyId").asText()); dataset.setInstrument(json.get("instrument").get("name").asText()); dataset.setPhysicalVariable(json.get("physicalVariable").asText()); dataset.setCMIP5VarName(json.get("CMIP5VarName").asText()); dataset.setUnits(json.get("units").asText()); dataset.setGridDimension(json.get("gridDimension").asText()); dataset.setSource(json.get("source").asText()); dataset.setStatus(json.get("status").asText()); dataset.setResponsiblePerson(json.get("responsiblePerson").asText()); dataset.setDataSourceName(json.get("dataSourceNameinWebInterface").asText()); dataset.setVariableName(json.get("variableNameInWebInterface").asText()); dataset.setDataSourceInput(json.get("dataSourceInputParameterToCallScienceApplicationCode").asText()); dataset.setVariableNameInput( json.get("variableNameInputParameterToCallScienceApplicationCode").asText()); String startTime = json.findPath("startTime").asText(); String endTime = json.findPath("endTime").asText(); Date tmpTime = null; try { tmpTime = (new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a")).parse(startTime); if (tmpTime != null) { dataset.setStartTime(new SimpleDateFormat("YYYYMM").format(tmpTime)); } } catch (ParseException e) { } try { tmpTime = (new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a")).parse(endTime); if (tmpTime != null) { dataset.setEndTime(new SimpleDateFormat("YYYYMM").format(tmpTime)); } } catch (ParseException e) { } dataSets.add(dataset); } return dataSets; }
From source file:vk.model.VKApiPhotoSize.java
/** * Creates dimension from {@code source}. Used in parsing. * If size is not specified copies calculates them based on internal algorithms. * @param source object in format, returned VK API, which is generated from the dimension * @param originalWidth original image width in pixels * @param originalHeight original image height in pixels *///from ww w . ja v a2 s . c o m public static VKApiPhotoSize parse(JsonNode source, int originalWidth, int originalHeight) { VKApiPhotoSize result = new VKApiPhotoSize(); result.src = source.get("src").asText(); result.width = source.get("width").asInt(); result.height = source.get("height").asInt(); String type = source.get("type").asText(); if (type != null) { result.type = type.charAt(0); } // ? , ? ? ? . // ? , ??, width height ??? ? . // ?? . if (result.width == 0 || result.height == 0) { fillDimensions(result, originalWidth, originalHeight); } return result; }