本文整理汇总了Java中com.fasterxml.jackson.databind.node.MissingNode类的典型用法代码示例。如果您正苦于以下问题:Java MissingNode类的具体用法?Java MissingNode怎么用?Java MissingNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MissingNode类属于com.fasterxml.jackson.databind.node包,在下文中一共展示了MissingNode类的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: push
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
/**
* Build an array of email subscribers and batch insert via bulk MailChimp API
* Reference: https://developer.mailchimp.com/documentation/mailchimp/reference/lists/#create-post_lists_list_id
*
* @param node the data
* @param task the task
* @return the report response
* @throws JsonProcessingException the json processing exception
*/
ReportResponse push(final ObjectNode node, PluginTask task)
throws JsonProcessingException
{
String endpoint = MessageFormat.format(mailchimpEndpoint + "/lists/{0}",
task.getListId());
JsonNode response = client.sendRequest(endpoint, HttpMethod.POST, node.toString(), task);
client.avoidFlushAPI("Process next request");
if (response instanceof MissingNode) {
ReportResponse reportResponse = new ReportResponse();
reportResponse.setErrors(new ArrayList<ErrorResponse>());
return reportResponse;
}
return mapper.treeToValue(response, ReportResponse.class);
}
示例5: deserialize
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
@Override
public Resource deserialize(JsonParser parser, DeserializationContext context) throws IOException {
TreeNode tree = parser.readValueAsTree();
Assert.isTrue(tree.path("rClass") != MissingNode.getInstance(),
"No 'rClass' field found. Cannot deserialize Resource JSON.");
RClass rClass = modelService.resolveRType(((TextNode) tree.path("rClass")).textValue());
if (rClass.isAbstract()) {
throw new AbstractRClassException(rClass);
}
Resource resource = factory.createResource(rClass);
TreeNode properties = tree.path("properties");
if (properties instanceof ObjectNode) {
populateProperties((ObjectNode) properties, resource);
}
return resource;
}
示例6: 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();
}
}
示例7: getJson
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
public JsonNode getJson() {
if (isValid()) {
return json;
} else {
return MissingNode.getInstance();
}
}
示例8: osDiskStatus
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
@Override
public EncryptionStatus osDiskStatus() {
if (!hasEncryptionExtension()) {
return EncryptionStatus.NOT_ENCRYPTED;
}
final JsonNode subStatusNode = instanceViewFirstSubStatus();
if (subStatusNode == null) {
return EncryptionStatus.UNKNOWN;
}
JsonNode diskNode = subStatusNode.path("os");
if (diskNode instanceof MissingNode) {
return EncryptionStatus.UNKNOWN;
}
return EncryptionStatus.fromString(diskNode.asText());
}
示例9: dataDiskStatus
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
@Override
public EncryptionStatus dataDiskStatus() {
if (!hasEncryptionExtension()) {
return EncryptionStatus.NOT_ENCRYPTED;
}
final JsonNode subStatusNode = instanceViewFirstSubStatus();
if (subStatusNode == null) {
return EncryptionStatus.UNKNOWN;
}
JsonNode diskNode = subStatusNode.path("data");
if (diskNode instanceof MissingNode) {
return EncryptionStatus.UNKNOWN;
}
return EncryptionStatus.fromString(diskNode.asText());
}
示例10: extractCapturedImageUri
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
private static String extractCapturedImageUri(String capturedResultJson) {
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode;
try {
rootNode = mapper.readTree(capturedResultJson);
} catch (IOException exception) {
throw new RuntimeException("Parsing JSON failed -" + capturedResultJson, exception);
}
JsonNode resourcesNode = rootNode.path("resources");
if (resourcesNode instanceof MissingNode) {
throw new IllegalArgumentException("Expected 'resources' node not found in the capture result -" + capturedResultJson);
}
String imageUri = null;
for (JsonNode resourceNode : resourcesNode) {
JsonNode propertiesNodes = resourceNode.path("properties");
if (!(propertiesNodes instanceof MissingNode)) {
JsonNode storageProfileNode = propertiesNodes.path("storageProfile");
if (!(storageProfileNode instanceof MissingNode)) {
JsonNode osDiskNode = storageProfileNode.path("osDisk");
if (!(osDiskNode instanceof MissingNode)) {
JsonNode imageNode = osDiskNode.path("image");
if (!(imageNode instanceof MissingNode)) {
JsonNode uriNode = imageNode.path("uri");
if (!(uriNode instanceof MissingNode)) {
imageUri = uriNode.asText();
}
}
}
}
}
}
if (imageUri == null) {
throw new IllegalArgumentException("Could not locate image uri under expected section in the capture result -" + capturedResultJson);
}
return imageUri;
}
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:40,代码来源:CreateVirtualMachinesUsingCustomImageOrSpecializedVHD.java
示例11: get
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
public static PrimitiveObject get( final JsonNode jsonNode ) throws IOException{
if( jsonNode instanceof TextNode ){
return new StringObj( ( (TextNode)jsonNode ).textValue() );
}
else if( jsonNode instanceof BooleanNode ){
return new BooleanObj( ( (BooleanNode)jsonNode ).booleanValue() );
}
else if( jsonNode instanceof IntNode ){
return new IntegerObj( ( (IntNode)jsonNode ).intValue() );
}
else if( jsonNode instanceof LongNode ){
return new LongObj( ( (LongNode)jsonNode ).longValue() );
}
else if( jsonNode instanceof DoubleNode ){
return new DoubleObj( ( (DoubleNode)jsonNode ).doubleValue() );
}
else if( jsonNode instanceof BigIntegerNode ){
return new StringObj( ( (BigIntegerNode)jsonNode ).bigIntegerValue().toString() );
}
else if( jsonNode instanceof DecimalNode ){
return new StringObj( ( (DecimalNode)jsonNode ).decimalValue().toString() );
}
else if( jsonNode instanceof BinaryNode ){
return new BytesObj( ( (BinaryNode)jsonNode ).binaryValue() );
}
else if( jsonNode instanceof POJONode ){
return new BytesObj( ( (POJONode)jsonNode ).binaryValue() );
}
else if( jsonNode instanceof NullNode ){
return NullObj.getInstance();
}
else if( jsonNode instanceof MissingNode ){
return NullObj.getInstance();
}
else{
return new StringObj( jsonNode.toString() );
}
}
示例12: 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));
}
示例13: checkContextData
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
private static void checkContextData(LogEvent logEvent, String mdcKeyRegex, final JsonNode rootNode) {
final Pattern mdcKeyPattern = mdcKeyRegex == null ? null : Pattern.compile(mdcKeyRegex);
logEvent.getContextData().forEach(new BiConsumer<String, Object>() {
@Override
public void accept(String key, Object value) {
JsonNode node = point(rootNode, "mdc", key);
boolean matches = mdcKeyPattern == null || mdcKeyPattern.matcher(key).matches();
if (matches) {
assertThat(node.asText()).isEqualTo(value);
} else {
assertThat(node).isEqualTo(MissingNode.getInstance());
}
}
});
}
示例14: 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();
}
示例15: createNodeMatcher
import com.fasterxml.jackson.databind.node.MissingNode; //导入依赖的package包/类
private static Matcher<JsonNode> createNodeMatcher(final JsonNode value) {
final JsonNodeType nodeType = value.getNodeType();
switch (nodeType) {
case ARRAY:
return IsJsonArray.jsonArray((ArrayNode) value);
case BINARY:
throw new UnsupportedOperationException(
"Expected value contains a binary node, which is not implemented.");
case BOOLEAN:
return IsJsonBoolean.jsonBoolean((BooleanNode) value);
case MISSING:
return IsJsonMissing.jsonMissing((MissingNode) value);
case NULL:
return IsJsonNull.jsonNull((NullNode) value);
case NUMBER:
return IsJsonNumber.jsonNumber((NumericNode) value);
case OBJECT:
return IsJsonObject.jsonObject((ObjectNode) value);
case POJO:
throw new UnsupportedOperationException(
"Expected value contains a POJO node, which is not implemented.");
case STRING:
return IsJsonText.jsonText((TextNode) value);
default:
throw new UnsupportedOperationException("Unsupported node type " + nodeType);
}
}