List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.pros.jsontransform.constraint.ConstraintType.java
public static void validate(final JsonNode constraintNode, final JsonNode resultNode, final ObjectTransformer transformer) throws ObjectTransformerException { String type = constraintNode.get(Constraint.$TYPE.toString()).asText().toUpperCase(); if (!JsonNodeType.valueOf(type).isValid(resultNode)) { throw new ObjectTransformerException("Constraint violation [" + Constraint.$TYPE.toString() + "]" + " on transform node " + transformer.getTransformNodeFieldName()); }//from w w w .j a v a 2s . c om }
From source file:enmasse.controller.flavor.FlavorParser.java
public static Map<String, Flavor> parse(JsonNode root) { Map<String, Flavor> flavorMap = new LinkedHashMap<>(); for (int i = 0; i < root.size(); i++) { Flavor flavor = parseFlavor(root.get(i)); flavorMap.put(flavor.name(), flavor); }/*from ww w .j a v a2s .co m*/ return flavorMap; }
From source file:com.ikanow.aleph2.data_model.utils.JsonUtils.java
/** Returns a nested sub-element from a path in dot notation, else empty * @param path in dot notation// w w w . j a va 2 s. co m * @return */ public static Optional<JsonNode> getProperty(final String path, final JsonNode obj) { final String[] paths = path.split("[.]"); final String last = paths[paths.length - 1]; JsonNode mutable_curr = obj; for (String p : paths) { final JsonNode j = mutable_curr.get(p); if (last == p) { return Optional.ofNullable(j).filter(__ -> !j.isNull()); } else if (null == j) { return Optional.empty(); } else if (j.isArray()) { // if it's an array get the first value - for anything more complicated need jpath mutable_curr = j.get(0); } else if (j.isObject()) { mutable_curr = j; } else return Optional.empty(); // not at the end of the chain and it's not something you can map through } return Optional.empty(); }
From source file:org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.java
/** * Detects current Elastic Search version by connecting to a existing instance. * It is a {@code GET} request to {@code /}. Returned JSON has server information * (including version)./*from www.j a v a 2 s . com*/ * * @param client low-level rest client connected to ES instance * @param mapper Jackson mapper instance used to parse responses * @return parsed version from ES, or {@link ElasticsearchVersion#UNKNOWN} * @throws IOException if couldn't connect to ES */ private static ElasticsearchVersion detectVersion(RestClient client, ObjectMapper mapper) throws IOException { HttpEntity entity = client.performRequest("GET", "/").getEntity(); JsonNode node = mapper.readTree(EntityUtils.toString(entity)); return ElasticsearchVersion.fromString(node.get("version").get("number").asText()); }
From source file:com.redhat.lightblue.crud.validator.RequiredChecker.java
/** * Returns the list of fields that are missing in the doc * * @param fieldMetadataPath Path of the required field * @param doc The document/*from ww w . j a v a 2 s . c o m*/ * * @return List of field instances that are not present in the doc. */ public static List<Path> getMissingFields(Path fieldMetadataPath, JsonDoc doc) { LOGGER.debug("Checking {}", fieldMetadataPath); int nAnys = fieldMetadataPath.nAnys(); List<Path> errors = new ArrayList<Path>(); if (nAnys == 0) { if (doc.get(fieldMetadataPath) == null) { errors.add(fieldMetadataPath); } } else { // The required field is a member of an object that's an element of an array // If the array element exists, then the member must exist in that object Path parent = fieldMetadataPath.prefix(-1); String fieldName = fieldMetadataPath.tail(0); LOGGER.debug("Checking {} under {}", fieldName, parent); KeyValueCursor<Path, JsonNode> cursor = doc.getAllNodes(parent); while (cursor.hasNext()) { cursor.next(); JsonNode parentObject = cursor.getCurrentValue(); LOGGER.debug("Checking {}", cursor.getCurrentKey()); if (parentObject.get(fieldName) == null) { errors.add(new Path(cursor.getCurrentKey() + "." + fieldName)); } } } LOGGER.debug("Errors:{}", errors); return errors; }
From source file:com.google.api.tools.framework.importers.swagger.MultiSwaggerParser.java
private static boolean isTopLevelSwaggerFile(JsonNode data) { return data.get(SWAGGER_VERSION_PROPERTY) != null && data.get(SWAGGER_VERSION_PROPERTY).toString().contains(CURRENT_SWAGGER_VERSION); }
From source file:com.pros.jsontransform.filter.ArrayFilterEquals.java
public static boolean evaluate(final JsonNode filterNode, final JsonNode elementNode, final ObjectTransformer transformer) throws ObjectTransformerException { boolean result = false; JsonNode filterArguments = filterNode.get(ArrayFilter.$EQUALS.name().toLowerCase()); JsonNode valueNode = transformer.transformValueNode(elementNode, filterArguments); JsonNode likeNode = filterArguments.path(ArrayFilter.ARGUMENT_WHAT); if (valueNode.equals(likeNode)) { result = true;// w w w.j a v a2 s.c om } return result; }
From source file:com.trusolve.ant.filters.SynapseAPISwaggerFilter.java
private static void fixGetPaths(JsonNode root) { Map<String, JsonNode> toAdd = new HashMap<String, JsonNode>(); JsonNode paths = root.get("paths"); if (paths != null && paths.isObject()) { ObjectNode pathsObject = (ObjectNode) paths; for (Iterator<Map.Entry<String, JsonNode>> i = paths.fields(); i.hasNext();) { Map.Entry<String, JsonNode> e = i.next(); String pathName = e.getKey(); // Check to see if this a template type if (pathName != null && pathName.contains("{")) { JsonNode pathDetail = e.getValue(); if (pathDetail != null && pathDetail.has("get")) { ObjectNode newPathDetail = pathDetail.deepCopy(); newPathDetail.remove("put"); newPathDetail.remove("post"); newPathDetail.remove("delete"); newPathDetail.remove("options"); newPathDetail.remove("head"); newPathDetail.remove("patch"); String newPathName = pathName + "?*"; toAdd.put(newPathName, newPathDetail); }/* w ww . j a va 2s . co m*/ } } for (Map.Entry<String, JsonNode> e : toAdd.entrySet()) { pathsObject.set(e.getKey(), e.getValue()); } } }
From source file:com.collective.celos.SlotState.java
public static SlotState fromJSONNode(SlotID id, JsonNode node) { SlotState.Status status = SlotState.Status.valueOf(node.get(STATUS_PROP).textValue()); String externalID = node.get(EXTERNAL_ID_PROP).textValue(); int retryCount = node.get(RETRY_COUNT_PROP).intValue(); return new SlotState(id, status, externalID, retryCount); }
From source file:mobile.vo.user.EducationExp.java
public static EducationExp create(JsonNode jobExpNode) { EducationExp exp = new EducationExp(); exp.exp = Json.newObject();/*from w w w.j ava 2s .co m*/ exp.exp.put("year", jobExpNode.hasNonNull("year") ? jobExpNode.get("year").asText() : ""); exp.exp.put("yearEnd", jobExpNode.hasNonNull("yearEnd") ? jobExpNode.get("yearEnd").asText() : jobExpNode.get("year").asText()); exp.exp.put("school", jobExpNode.hasNonNull("school") ? jobExpNode.get("school").asText() : ""); exp.exp.put("major", jobExpNode.hasNonNull("major") ? jobExpNode.get("major").asText() : ""); exp.exp.put("academicDegree", jobExpNode.hasNonNull("academicDegree") ? jobExpNode.get("academicDegree").asText() : ""); exp.exp.put("eduInfo", jobExpNode.hasNonNull("eduInfo") ? jobExpNode.get("eduInfo").asText() : ""); return exp; }