@Override protected JsonNode _at(JsonPointer ptr) { // will only allow direct matches, but no traversal through // (base class checks for direct match) return MissingNode.getInstance(); }
@Override public JsonNode path(int index) { return MissingNode.getInstance(); }
@Override public final JsonNode path(int index) { return MissingNode.getInstance(); }
@Override public final JsonNode path(String fieldName) { return MissingNode.getInstance(); }
@Override public JsonNode path(String fieldName) { return MissingNode.getInstance(); }
@Override public JsonNode path(String fieldName) { JsonNode n = _children.get(fieldName); if (n != null) { return n; } return MissingNode.getInstance(); }
@Override public JsonNode path(int index) { if (index >= 0 && index < _children.size()) { return _children.get(index); } return MissingNode.getInstance(); }
private JsonNode readJsonNode(JsonNode jsonNode, String field) { return jsonNode.has(field) ? jsonNode.get(field) : MissingNode.getInstance(); } }
private JsonNode readJsonNode(JsonNode jsonNode, String field) { return jsonNode.has(field) ? jsonNode.get(field) : MissingNode.getInstance(); } }
@Override public final JsonNode findPath(String fieldName) { JsonNode value = findValue(fieldName); if (value == null) { return MissingNode.getInstance(); } return value; }
private JsonNode readJsonNode(JsonNode jsonNode, String field) { return jsonNode.has(field) ? jsonNode.get(field) : MissingNode.getInstance(); } }
@Override public JsonNode evaluate(FunctionArgs args, EvaluationContext context) { final String value = valueParam.required(args, context); try { return objectMapper.readTree(value); } catch (IOException e) { log.warn("Unable to parse JSON", e); } return MissingNode.getInstance(); }
private JsonNode readJsonNode(JsonNode jsonNode, String field) { return jsonNode.has(field) ? jsonNode.get(field) : MissingNode.getInstance(); } }
private static JsonNode locateNode(JsonNode tree, DecoderColumnHandle columnHandle) { String mapping = columnHandle.getMapping(); checkState(mapping != null, "No mapping for %s", columnHandle.getName()); JsonNode currentNode = tree; for (String pathElement : Splitter.on('/').omitEmptyStrings().split(mapping)) { if (!currentNode.has(pathElement)) { return MissingNode.getInstance(); } currentNode = currentNode.path(pathElement); } return currentNode; } }
public JsonNode getFirstEntryJsonNode() { JsonNode memberJsonNode = getMemberJsonNode(); if (!memberJsonNode.isArray() || (memberJsonNode.size() == 0)) { if (_log.isDebugEnabled()) { _log.debug("Unable to fetch the member node"); } return MissingNode.getInstance(); } return memberJsonNode.get(0); }
/** * Parses the given JsonNode which is a <code>@context</code> node and find * the value of the <code>@vocab</code> node. * * @param contextJsonNode * @return <code>String</code> the Vocab's value e.g "@vocab": * "http://schema.org" otherwise empty String * @review */ public String getVocabulary(JsonNode contextJsonNode) { JsonNode jsonNode = contextJsonNode.findValue(JSONLDConstants.VOCAB); if (jsonNode == null) { JsonNode missingNode = MissingNode.getInstance(); return missingNode.asText(); } return jsonNode.asText(); }
/** * Open and parse the JSON file at the given path into a Jackson JSON tree. Comments and unquoted keys are allowed. * Returns null if the file does not exist, * Returns null if the file contains syntax errors or cannot be parsed for some other reason. * * We do not require any JSON config files to be present because that would get in the way of the simplest * rapid deployment workflow. Therefore we return an empty JSON node when the file is missing, causing us to fall * back on all the default values as if there was a JSON file present with no fields defined. */ public static JsonNode loadJson (File file) { try (FileInputStream jsonStream = new FileInputStream(file)) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); JsonNode config = mapper.readTree(jsonStream); LOG.info("Found and loaded JSON configuration file '{}'", file); return config; } catch (FileNotFoundException ex) { LOG.info("File '{}' is not present. Using default configuration.", file); return MissingNode.getInstance(); } catch (Exception ex) { LOG.error("Error while parsing JSON config file '{}': {}", file, ex.getMessage()); System.exit(42); // probably "should" be done with an exception return null; } }
private JsonNode getNodeInfo(String nodeId) { if (nodeId == null || nodeId.isEmpty()) { return MissingNode.getInstance(); } final NodesInfo request = new NodesInfo.Builder().addNode(nodeId).build(); final JestResult result = JestUtils.execute(jestClient, request, () -> "Couldn't read information of Elasticsearch node " + nodeId); return result.getJsonObject().path("nodes").path(nodeId); }
/** * Method for locating node specified by given JSON pointer instances. * Method will never return null; if no matching node exists, * will return a node for which {@link #isMissingNode()} returns true. * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link #isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(JsonPointer ptr) { // Basically: value nodes only match if we have "empty" path left if (ptr.matches()) { return this; } JsonNode n = _at(ptr); if (n == null) { return MissingNode.getInstance(); } return n.at(ptr.tail()); }
@Test public void shouldReturnBaseClaimWhenParsingMissingNode() throws Exception { JsonNode value = MissingNode.getInstance(); Claim claim = claimFromNode(value); assertThat(claim, is(notNullValue())); assertThat(claim, is(instanceOf(NullClaim.class))); assertThat(claim.isNull(), is(true)); }