Java Code Examples for com.fasterxml.jackson.databind.node.MissingNode#getInstance()
The following examples show how to use
com.fasterxml.jackson.databind.node.MissingNode#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoveOperation.java From centraldogma with Apache License 2.0 | 6 votes |
@Override JsonNode apply(final JsonNode node) { if (path.toString().isEmpty()) { return MissingNode.getInstance(); } ensureExistence(node); final JsonNode parentNode = node.at(path.head()); final String raw = path.last().getMatchingProperty(); if (parentNode.isObject()) { ((ObjectNode) parentNode).remove(raw); } else { ((ArrayNode) parentNode).remove(Integer.parseInt(raw)); } return node; }
Example 2
Source File: RemoveIfExistsOperation.java From centraldogma with Apache License 2.0 | 6 votes |
@Override JsonNode apply(final JsonNode node) { if (path.toString().isEmpty()) { return MissingNode.getInstance(); } final JsonNode found = node.at(path); if (found.isMissingNode()) { return node; } final JsonNode parentNode = node.at(path.head()); final String raw = path.last().getMatchingProperty(); if (parentNode.isObject()) { ((ObjectNode) parentNode).remove(raw); } else if (parentNode.isArray()) { ((ArrayNode) parentNode).remove(Integer.parseInt(raw)); } return node; }
Example 3
Source File: JsonNodeValue.java From mybatis-jackson with MIT License | 6 votes |
/** * Return COPY of JSON node value (will parse node from string at first call). * WARNING if object constructed with invalid JSON string, exception will be thrown. * * @return Copy of valid JsonNode or MissingNode if no data. * @throws RuntimeException On JSON parsing errors. */ public JsonNode get() throws RuntimeException { if (!isPresent()) { return MissingNode.getInstance(); } if (value == null) { synchronized (this) { if (value == null) { try { value = ReaderWriter.readTree(source); } catch (Exception ex) { throw new RuntimeException("Can not parse JSON string. " + ex.getMessage(), ex); } } } } return value.deepCopy(); }
Example 4
Source File: JsonRowDecoder.java From presto with Apache License 2.0 | 5 votes |
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; }
Example 5
Source File: JsonNode.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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()); }
Example 6
Source File: AbstractResourceDiff.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
protected JsonNode lookupPath(JsonNode source, String path) { JsonNode s = source; for (String component : path.substring(1).split("/")) { if (s.isArray()) { try { s = s.path(Integer.parseInt(component)); } catch (NumberFormatException e) { return MissingNode.getInstance(); } } else { s = s.path(component); } } return s; }
Example 7
Source File: TreeNodeTypeHandler.java From mybatis-jackson with MIT License | 5 votes |
private TreeNode fromString(String source) { if (source == null || source.isEmpty()) { // This is where we replace null result with empty node return MissingNode.getInstance(); } else { // I really hope that source will be valid JSON string (^_^) return new TreeNodeLazyWrapper(source); } }
Example 8
Source File: JsonUtils.java From template-compiler with Apache License 2.0 | 5 votes |
/** * Attempt to decode the input as JSON. Returns the {@link JsonNode} if * the decode is successful. * * If the decode fails and the {@code failQuietly} flag is true, returns a * {@link MissingNode}. Otherwise an {@link IllegalArgumentException} will * be thrown. */ public static JsonNode decode(String input, boolean failQuietly) { try { return MAPPER.readTree(input); } catch (IOException e) { if (failQuietly) { return MissingNode.getInstance(); } throw new IllegalArgumentException("Unable to decode JSON", e); } }
Example 9
Source File: JsonKinesisRowDecoder.java From presto-kinesis with Apache License 2.0 | 5 votes |
private static JsonNode locateNode(JsonNode tree, KinesisColumnHandle 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; }
Example 10
Source File: JsonNodeClaimTest.java From java-jwt with MIT License | 5 votes |
@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)); }
Example 11
Source File: Context.java From template-compiler with Apache License 2.0 | 4 votes |
public Context(JsonNode node, StringBuilder buf, Locale locale) { this.currentFrame = new Frame(null, node == null ? MissingNode.getInstance() : node); this.buf = buf == null ? new StringBuilder() : buf; this.javaLocale = locale == null ? Locale.US : locale; }