当前位置: 首页>>代码示例>>Java>>正文


Java JsonNode.asText方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.asText方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.asText方法的具体用法?Java JsonNode.asText怎么用?Java JsonNode.asText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.asText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleErrorResponse

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
    String errorCode = null;

    // Parse the error stream returned from the service.
    if(errorStream != null) {
        String errorResponse = IOUtils.toString(errorStream);

        try {
            JsonNode node = Jackson.jsonNodeOf(errorResponse);
            JsonNode code = node.get("code");
            JsonNode message = node.get("message");
            if (code != null && message != null) {
                errorCode = code.asText();
                responseMessage = message.asText();
            }
        } catch (Exception exception) {
            LOG.debug("Unable to parse error stream");
        }
    }

    AmazonServiceException ase = new AmazonServiceException(responseMessage);
    ase.setStatusCode(statusCode);
    ase.setErrorCode(errorCode);
    throw ase;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:26,代码来源:EC2CredentialsUtils.java

示例2: suppressHostByProvider

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Gets provider names from which SegmentRouting does not learn host info.
 *
 * @return array of provider names that need to be ignored
 */
public Set<String> suppressHostByProvider() {
    if (!object.has(SUPPRESS_HOST_BY_PROVIDER)) {
        return ImmutableSet.of();
    }

    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_HOST_BY_PROVIDER);
    for (JsonNode jsonNode : arrayNode) {
        String providerName = jsonNode.asText(null);
        if (providerName == null) {
            return null;
        }
        builder.add(providerName);
    }
    return builder.build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:SegmentRoutingAppConfig.java

示例3: processSubInclude

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void processSubInclude(Query query, CanInclude parentInclude, JsonNode includeNode) throws QueryException {
	if (includeNode instanceof ObjectNode) {
		ObjectNode innerInclude = (ObjectNode)includeNode;
		parentInclude.addInclude(parseInclude(query, innerInclude, null, parentInclude));
	} else if (includeNode.isTextual()) {
		String includeName = includeNode.asText();
		if (includeName.contains(":")) {
			parentInclude.addInclude(getDefineFromFile(includeName));
		} else {
			Include otherInclude = query.getDefine(includeName);
			if (otherInclude == null) {
				throw new QueryException("Cannot find define \"" + includeName + "\"");
			}
			parentInclude.addInclude(otherInclude);
		}
	} else {
		throw new QueryException("\"include\" must be of type object or string");
	}
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:20,代码来源:JsonQueryObjectModelConverter.java

示例4: extractCapturedImageUri

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的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

示例5: getJsonValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static Object getJsonValue(JsonNode input, String name, Class type, boolean isRequired, Object defaultValue) throws IllegalArgumentException {
  JsonNode node = input.findPath(name);

  if (node.isMissingNode() || node.isNull()) {
    if (isRequired) {
      throw new IllegalArgumentException(name + " is required!");
    } else {
      return defaultValue;
    }
  }

  if (type.equals(String.class)) {
    return node.textValue();
  }

  if (type.equals(Integer.class)) {
    return node.asInt();
  }

  if (type.equals(Long.class)) {
    return node.asLong();
  }

  if (type.equals(Boolean.class)) {
    return node.asBoolean();
  }

  if (type.equals(Double.class)) {
    return node.asDouble();
  }

  return node.asText();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:34,代码来源:JsonUtil.java

示例6: deserialize

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Service deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
  ObjectMapper mapper = (ObjectMapper) p.getCodec();
  if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
    return new GenericService(null, p.getValueAsString());
  }
  ObjectNode obj = mapper.readTree(p);
  if (isV1ImageService(obj)) {
    return parseV1Service(obj);
  } else if (isImageService(obj)) {
    return mapper.treeToValue(obj, ImageService.class);
  }

  String context = null;
  if (obj.has("@context")) {
    context = obj.get("@context").asText();
  }
  JsonNode profileNode = obj.get("profile");
  String profile = null;
  if (profileNode != null) {
    profile = profileNode.asText();
  }
  if (Objects.equals(context, ContentSearchService.CONTEXT)) {
    if (Objects.equals(profile, AutocompleteService.PROFILE)) {
      return mapper.treeToValue(obj, AutocompleteService.class);
    } else {
      return mapper.treeToValue(obj, ContentSearchService.class);
    }
  } else if (Objects.equals(context, AccessCookieService.CONTEXT)) {
    return mapper.treeToValue(obj, AccessCookieService.class);
  } else if (Objects.equals(context, GeoService.CONTEXT)) {
    return mapper.treeToValue(obj, GeoService.class);
  } else if (Objects.equals(context, PhysicalDimensionsService.CONTEXT)) {
    return mapper.treeToValue(obj, PhysicalDimensionsService.class);
  } else {
    return mapper.treeToValue(obj, GenericService.class);
  }
}
 
开发者ID:dbmdz,项目名称:iiif-apis,代码行数:39,代码来源:ServiceDeserializer.java

示例7: getLink

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
protected String getLink(ObjectNode rootNode, String linkName)
{
	ObjectNode linksNode = (ObjectNode) rootNode.get("links");
	if( linksNode == null )
	{
		return null;
	}
	JsonNode linkNode = linksNode.get(linkName);
	if( linkNode == null )
	{
		return null;
	}
	return linkNode.asText();
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:AbstractRestApiTest.java

示例8: moveBuffersToBody

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public void moveBuffersToBody(ObjectNode scene, GlbBody body) throws Exception {
	// Modify the GLTF data to reference the buffer in the body instead of
	// external references.

	JsonNode buffersNode = scene.get("buffers");
	Iterator<String> fieldIter = buffersNode.fieldNames();
	while (fieldIter.hasNext()) {
		String fieldKey = fieldIter.next();
		JsonNode gltfBufferNode = buffersNode.get(fieldKey);
		JsonNode typeNode = gltfBufferNode.get("type");
		String typeText = typeNode.asText();
		if (typeText != null && !typeText.equals("arraybuffer")) {
			throw new Exception("buffer type " + typeText + " not supported: " + fieldKey);
		}
		JsonNode uriNode = gltfBufferNode.get("uri");
		String uri = uriNode.asText();

		JsonNode byteLengthNode = gltfBufferNode.get("byteLength");
		int byteLength = byteLengthNode.asInt();

		Part part = body.add(uri, byteLength);

		JsonNode extrasNode = gltfBufferNode.get("extras");
		if (extrasNode == null) {
			extrasNode = jsonNodeFactory.objectNode();
			((ObjectNode) gltfBufferNode).set("extras", extrasNode);
		}
		((ObjectNode) extrasNode).put("byteOffset", part.offset);

	}

}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:33,代码来源:Gltf2glbConvertor.java

示例9: doGetEC2InstanceRegion

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
static String doGetEC2InstanceRegion(final String json) {
    if (null != json) {
        try {
            JsonNode node = MAPPER.readTree(json.getBytes(StringUtils.UTF8));
            JsonNode region = node.findValue(REGION);
            return region.asText();
        } catch (Exception e) {
            log.warn("Unable to parse EC2 instance info (" + json
                     + ") : " + e.getMessage(), e);
        }
    }
    return null;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:14,代码来源:EC2MetadataUtils.java

示例10: parseErrorMessage

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Parse the error message from the response.
 *
 * @return Error Code of exceptional response or null if it can't be determined
 */
public String parseErrorMessage(HttpResponse httpResponse, JsonNode jsonNode) {
    // If X_AMZN_ERROR_MESSAGE is present, prefer that. Otherwise check the JSON body.
    final String headerMessage = httpResponse.getHeader(X_AMZN_ERROR_MESSAGE);
    if (headerMessage != null) {
        return headerMessage;
    }
    for (String field : errorMessageJsonLocations) {
        JsonNode value = jsonNode.get(field);
        if (value != null && value.isTextual()) {
            return value.asText();
        }
    }
    return null;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:20,代码来源:JsonErrorMessageParser.java

示例11: getConfig

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Returns value of a given path. If the path is missing, show log and return
 * null.
 *
 * @param path path
 * @return value or null
 */
private String getConfig(JsonNode jsonNode, String path) {
    jsonNode = jsonNode.path(path);

    if (jsonNode.isMissingNode()) {
        log.error("{} is not configured", path);
        return null;
    } else {
        return jsonNode.asText();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:XosAccessConfig.java

示例12: handlePackageJson

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
AddOnInfoAndVersions handlePackageJson(AddOnToIndex addOnToIndex, String packageJson) throws IOException {
	AddOnInfoAndVersions info = AddOnInfoAndVersions.from(addOnToIndex);
	info.setHostedUrl(hostedUrlFor(addOnToIndex));
	ObjectNode obj = new ObjectMapper().readValue(packageJson, ObjectNode.class);
	if (StringUtils.isEmpty(info.getName())) {
		info.setName(obj.get("name").asText());
	}
	if (StringUtils.isEmpty(info.getDescription())) {
		info.setDescription(obj.get("desc").asText());
	}
	String expectedFileExtension = "." + info.getType().getFileExtension();
	for (JsonNode node : obj.path("versions")) {
		String versionString = node.asText();
		// TODO do we need to GET the version and make sure it's published?
		ArrayNode arr = restTemplateBuilder.basicAuthorization(bintrayUsername, bintrayApiKey).build()
				.getForObject(getVersionFilesUrlFor(addOnToIndex, versionString), ArrayNode.class);
		for (JsonNode fileNode : arr) {
			if (fileNode.get("name").asText().endsWith(expectedFileExtension)) {
				// found the type of file we want, so assume this is the right file.
				// TODO maybe test that it has the version number in it?
				AddOnVersion version = new AddOnVersion();
				version.setVersion(new Version(versionString));
				version.setReleaseDatetime(OffsetDateTime.parse(fileNode.get("created").asText()));
				version.setDownloadUri(downloadUriFor(addOnToIndex, fileNode.get("path").asText()));
				info.addVersion(version);
				break;
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Skipping file: " + arr.get("name").asText());
			}
		}
	}
	return info;
}
 
开发者ID:openmrs,项目名称:openmrs-contrib-addonindex,代码行数:35,代码来源:Bintray.java

示例13: getStringValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private String getStringValue(String field) {
    JsonNode name = object.path(field);
    return name.isMissingNode() ? "" : name.asText();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:OpticalPortConfig.java

示例14: matchesSafely

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public boolean matchesSafely(JsonNode jsonIntent, Description description) {
    // check id
    final String jsonId = jsonIntent.get("id").asText();
    final String id = intent.id().toString();
    if (!jsonId.equals(id)) {
        description.appendText("id was " + jsonId);
        return false;
    }

    // check application id
    final JsonNode jsonAppIdNode = jsonIntent.get("appId");

    final String jsonAppId = jsonAppIdNode.asText();
    final String appId = intent.appId().name();
    if (!jsonAppId.equals(appId)) {
        description.appendText("appId was " + jsonAppId);
        return false;
    }

    // check intent type
    final String jsonType = jsonIntent.get("type").asText();
    final String type = intent.getClass().getSimpleName();
    if (!jsonType.equals(type)) {
        description.appendText("type was " + jsonType);
        return false;
    }

    // check resources array
    final JsonNode jsonResources = jsonIntent.get("resources");
    if (intent.resources() != null) {
        if (intent.resources().size() != jsonResources.size()) {
            description.appendText("resources array size was "
                                   + Integer.toString(jsonResources.size()));
            return false;
        }
        for (final NetworkResource resource : intent.resources()) {
            boolean resourceFound = false;
            final String resourceString = resource.toString();
            for (int resourceIndex = 0; resourceIndex < jsonResources.size(); resourceIndex++) {
                final JsonNode value = jsonResources.get(resourceIndex);
                if (value.asText().equals(resourceString)) {
                    resourceFound = true;
                }
            }
            if (!resourceFound) {
                description.appendText("resource missing " + resourceString);
                return false;
            }
        }
    } else if (jsonResources.size() != 0) {
        description.appendText("resources array empty");
        return false;
    }

    if (intent instanceof ConnectivityIntent) {
        return matchConnectivityIntent(jsonIntent, description);
    } else {
        description.appendText("class of intent is unknown");
        return false;
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:63,代码来源:IntentJsonMatcher.java

示例15: fromJsonNode

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void fromJsonNode(JsonNode node) {
    JsonNodeType nodeType = node.getNodeType();

    switch (nodeType) {
        case STRING:
            type = Schema.Type.STRING;
            value = node.asText();
            break;

        case NUMBER:
            double number = node.asDouble();

            if (number == Math.floor(number)) {
                type = Schema.Type.INTEGER;
                value = (int) number;
            } else {
                type = Schema.Type.FLOAT;
                value = number;
            }
            break;

        case BOOLEAN:
            type = Schema.Type.BOOLEAN;
            value = node.asBoolean();
            break;

        case ARRAY:
            List<Node> list = new LinkedList<>();

            type = Schema.Type.LIST;

            for (int i = 0; i < node.size(); i++) {
                list.add(new Node(node.get(i)));
            }

            value = list;
            break;

        case OBJECT:
            Map<String, Node> struct = new HashMap<>();

            type = Schema.Type.STRUCT;

            for (Iterator<String> properties = node.fieldNames(); properties.hasNext(); ) {
                String property = properties.next();
                struct.put(property, new Node(node.get(property)));
            }

            value = struct;
            break;

        default:
            throw new RuntimeException("Unsupported JSON type");
    }
}
 
开发者ID:antology,项目名称:a6y-server,代码行数:56,代码来源:Node.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.asText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。