本文整理汇总了Java中com.fasterxml.jackson.databind.node.MissingNode.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java MissingNode.getInstance方法的具体用法?Java MissingNode.getInstance怎么用?Java MissingNode.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.node.MissingNode
的用法示例。
在下文中一共展示了MissingNode.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
@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;
}
示例2: findByCohort
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
/**
* Traverses the argument {@link JsonNode} to find any contained
* {@code JsonNode JsonNodes} which match the argument cohort, if
* present.
*
* If {@code node} is an {@code ArrayNode}, then the array is
* traversed and the first matching filter node, if any, is
* returned.
*
* @param node A {@code JsonNode} to traverse in search of cohort
* information.
* @param cohortOpt An optional cohort string to match against the
* argument {@code JsonNode}.
* @return A {@code JsonNode} matching the specified cohort, or else
* {@link MissingNode}.
*/
public static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt) {
if (node.isObject() && ToggleJsonNode.matchesCohort(node, cohortOpt)) {
return node;
} else if (node.isArray()) {
final Iterator<JsonNode> iterator = node.elements();
while (iterator.hasNext()) {
final JsonNode containedNode = iterator.next();
if (containedNode.isObject() && ToggleJsonNode.matchesCohort(containedNode, cohortOpt)) {
return containedNode;
}
}
return MissingNode.getInstance();
} else {
return MissingNode.getInstance();
}
}
示例3: searchKey
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
/**
* Recursively search for the JsonNode for the specified key. If found, this function will return an ObjectNode containing the key with underlying JsonNode.
* For instance, if searching for "key2" in JSON "{key1:{key2:{key3:value}}}" this will return "{key2:{key3:value}}"
* @param jn the JsonNode to search in
* @param key the key to search for
* @return the found object with {key:JsonNode} or MissingNode if not found
*/
public JsonNode searchKey(JsonNode jn, String key){
//this is a null node or a leaf node
if(jn == null || !jn.isContainerNode()) {
return MissingNode.getInstance();
}
//yay, found it!
//extract value and place it in clean wrapper ObjectNode with the key
if(jn.has(key)) {
return om.createObjectNode().set(key, jn.get(key));
}
//not found on this level... try to go deeper
for (JsonNode child : jn) {
if (child.isContainerNode()) {
JsonNode childResult = searchKey(child, key);
if (childResult != null && !childResult.isMissingNode()) {
return childResult;
}
}
}
// not found at all
return MissingNode.getInstance();
}
示例4: fromString
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
/**
* Constructs a {@link JsonNode} from a JSON string.
*
* @param json A string encoding a JSON object
* @return A {@code JsonNode} if the argument string is valid, otherwise
* {@link MissingNode}.
*/
public static JsonNode fromString(String json) {
try {
return DEFAULT_OBJECT_READER.readTree(json);
} catch (IOException err) {
return MissingNode.getInstance();
}
}
示例5: getJson
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
public JsonNode getJson() {
if (isValid()) {
return json;
} else {
return MissingNode.getInstance();
}
}
示例6: shouldReturnBaseClaimWhenParsingMissingNode
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
@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));
}
示例7: evaluate
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
@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();
}
示例8: decode
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例9: get
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
/**
* Uses a String path to create a List of keys in order to move
* through a nested ${@link JsonNode} in order to find a specific
* value. If the value is found, it is returned. If it can not be
* found, a ${@link MissingNode} will be returned.
*
* @param node the node to use for the search
* @param path the path to find the value for
* @return a ${@link JsonNode} if found, a ${@link MissingNode} if not
* @throws ParseException if any parsing issues occur
*/
public static JsonNode get(JsonNode node, String path) throws ParseException {
// check for bad targets
if (node == null) {
return MissingNode.getInstance();
}
// create a list of keys from the path
List<NotedKey> keys = keys(path);
// store a cheap reference
JsonNode tmp = node;
// grab length
int lastIndex = keys.size() - 1;
// go through every key we have (except the last)
for(int i = 0; i < lastIndex; i++) {
tmp = DotUtils.findNode(tmp, keys.get(i));
// if we've hit a dead end
if (tmp.isMissingNode() || tmp.isNull()) {
// short-circuit
return tmp;
}
}
// get the last key from the list
NotedKey key = keys.get(lastIndex);
// if the key is a Number
if (key.isNumber()) {
// return the ArrayNode index
return tmp.path(key.asNumber());
}
// return the ObjectNode value
return tmp.path(key.asString());
}
示例10: locateNode
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
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;
}
示例11: locateNode
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
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;
}
示例12: readJson
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
private JsonNode readJson (final byte[] data) {
if (data == null) {
return MissingNode.getInstance ();
}
final String stringContent = new String (data, Charset.forName ("UTF-8"));
try {
return new ObjectMapper().readTree (stringContent);
} catch (IOException e) {
log.error (e, "Unable to read ZooKeeper service payload, ignoring.");
return MissingNode.getInstance ();
}
}
示例13: readJsonNode
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
private JsonNode readJsonNode(JsonNode jsonNode, String field) {
return jsonNode.has(field) ? jsonNode.get(field) : MissingNode.getInstance();
}
示例14: Context
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
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.getDefault() : locale;
// this.cldrLocale = ??? TODO: replace with lookup
}
示例15: sendRequest
import com.fasterxml.jackson.databind.node.MissingNode; //导入方法依赖的package包/类
public JsonNode sendRequest(final String endpoint, final HttpMethod method, final String content,
final MailChimpOutputPluginDelegate.PluginTask task)
{
try (final Jetty92RetryHelper retryHelper = createRetryHelper(task)) {
final String authorizationHeader = getAuthorizationHeader(task);
String responseBody = retryHelper.requestWithRetry(
new StringJetty92ResponseEntityReader(task.getTimeoutMillis()),
new Jetty92SingleRequester()
{
@Override
public void requestOnce(HttpClient client, Response.Listener responseListener)
{
Request request = client
.newRequest(endpoint)
.timeout(task.getTimeoutMillis(), TimeUnit.MILLISECONDS)
.accept("application/json")
.method(method);
if (method == HttpMethod.POST || method == HttpMethod.PUT) {
request.content(new StringContentProvider(content), "application/json;utf-8");
}
if (!authorizationHeader.isEmpty()) {
request.header("Authorization", authorizationHeader);
}
request.send(responseListener);
}
@Override
public boolean isResponseStatusToRetry(Response response)
{
int status = response.getStatus();
return status == 429 || status / 100 != 4;
}
@Override
protected boolean isExceptionToRetry(Exception exception)
{
LOG.error("Exception to retry.", exception);
// This check is to make sure the exception is retryable, e.g: server not found, internal server error...
if (exception instanceof ConfigException || exception instanceof ExecutionException) {
return toRetry((Exception) exception.getCause());
}
return exception instanceof TimeoutException || super.isExceptionToRetry(exception);
}
});
return responseBody != null && !responseBody.isEmpty() ? parseJson(responseBody) : MissingNode.getInstance();
}
catch (Exception ex) {
LOG.error("Exception occurred while sending request.", ex);
throw Throwables.propagate(ex);
}
}