當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNode.findValue方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.JsonNode.findValue方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonNode.findValue方法的具體用法?Java JsonNode.findValue怎麽用?Java JsonNode.findValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.findValue方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getEventFromJson

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Parse an object node in order to create an {@link Event} object
 *
 * @param objectNode object node to convert to {@link Event}
 * @return {@link Event} converted format
 * @see TwitterMock#SOURCE
 */
@Override
public Event getEventFromJson(ObjectNode objectNode) {
    Date startDate = Date.from(Instant.ofEpochMilli(objectNode.findValue("timestamp_ms").asLong()));
    Date endDate = Date.from(Instant.now());
    JsonNode jsonNode = objectNode.findValue("place");
    JsonNode jsonCoordinates = jsonNode.findValue("coordinates");
    String description = objectNode.findValue("text").toString();
    LatLong latLong = jsonToLatLong(jsonCoordinates);
    try {
        return new Event(latLong, startDate, endDate, description, SOURCE);
    } catch (IllegalArgumentException | NullPointerException err) {
        LOGGER.error(err.getMessage());
        return null;
    }
}
 
開發者ID:IKB4Stream,項目名稱:IKB4Stream,代碼行數:23,代碼來源:TwitterMock.java

示例2: apply

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@Override
public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, Schema schema) {
    List<String> requiredFieldMethods = new ArrayList<String>();

    JsonNode properties = schema.getContent().get("properties");

    for (Iterator<JsonNode> iterator = node.elements(); iterator.hasNext(); ) {
        String requiredArrayItem = iterator.next().asText();
        if (requiredArrayItem.isEmpty()) {
            continue;
        }

        JsonNode propertyNode = null;

        if (properties != null) {
            propertyNode = properties.findValue(requiredArrayItem);
        }

        String fieldName = ruleFactory.getNameHelper().getPropertyName(requiredArrayItem, propertyNode);
        JFieldVar field = jclass.fields().get(fieldName);

        if (field == null) {
            continue;
        }

        addJavaDoc(field);

        if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) {
            addNotNullAnnotation(field);
        }

        if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations()) {
            addNonnullAnnotation(field);
        }

        requiredFieldMethods.add(getGetterName(fieldName, field.type(), node));
        requiredFieldMethods.add(getSetterName(fieldName, node));
    }

    updateGetterSetterJavaDoc(jclass, requiredFieldMethods);

    return jclass;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:44,代碼來源:RequiredArrayRule.java

示例3: extractAttributesFromResourceAsJson

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private String extractAttributesFromResourceAsJson(Resource resource) throws IOException {

		JsonApiResponse response = new JsonApiResponse();
		response.setEntity(resource);
		// deserialize using the objectMapper so it becomes json-api
		String newRequestBody = objectMapper.writeValueAsString(resource);
		JsonNode node = objectMapper.readTree(newRequestBody);
		JsonNode attributes = node.findValue("attributes");
		return objectMapper.writeValueAsString(attributes);

	}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:12,代碼來源:ResourcePatch.java

示例4: jsonToLatLong

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Parse a json node object in order to create a valid {@link LatLong} object
 *
 * @param objectNode {@link LatLong} in JSON format
 * @return a valid {@link LatLong}
 * @see LatLong
 * @see DBpediaMock#VALUE
 */
private static LatLong jsonToLatLong(JsonNode objectNode) {
    JsonNode latitudeNode = objectNode.findValue("latitude");
    JsonNode longitudeNode = objectNode.findValue("longitude");
    if (latitudeNode != null && longitudeNode != null) {
        double latitude = latitudeNode.findValue(VALUE).asDouble();
        double longitude = longitudeNode.findValue(VALUE).asDouble();
        return new LatLong(latitude, longitude);
    }
    return null;
}
 
開發者ID:IKB4Stream,項目名稱:IKB4Stream,代碼行數:19,代碼來源:DBpediaMock.java

示例5: 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

示例6: 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:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:14,代碼來源:EC2MetadataUtils.java

示例7: parse

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private static C4CTicket parse(String content) throws JsonProcessingException, IOException, C4CTicketNotFoundException {
	ObjectMapper mapper = new ObjectMapper();
	JsonNode jNode = mapper.readTree(content);
	JsonNode resultsArray = jNode.findValue(RESULTS_JSON_TREE_NODE);
	if(resultsArray.isNull() || !resultsArray.elements().hasNext()){
		throw new C4CTicketNotFoundException();
	}
	
	C4CTicket c4cTicket = createC4CTicketObject(jNode);
	return c4cTicket;
}
 
開發者ID:SAP,項目名稱:cloud-c4c-ticket-duplicate-finder-ext,代碼行數:12,代碼來源:C4CTicketService.java

示例8: isNotNull

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private boolean isNotNull(JsonNode jsonNode, String field){
	
	return jsonNode.findValue(field) != null && !jsonNode.get(field).isNull();
}
 
開發者ID:wesley-ramos,項目名稱:spring-multitenancy,代碼行數:5,代碼來源:TenantStrategyJson.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.findValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。