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


Java JsonNode.path方法代码示例

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


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

示例1: parseSpecificAQIMessageNode

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
SpecificAQIMessage parseSpecificAQIMessageNode(JsonNode specificMsgNode){
String pollutantCode = specificMsgNode.path("code").asText();
List<SpecificAQILevelMessage> specificAQILevelMessages = new ArrayList<SpecificAQILevelMessage>();

JsonNode specificAQLLevelMessagesNode = specificMsgNode.path("aqiLevel");
for(JsonNode aqiLevelMessageNode: specificAQLLevelMessagesNode){
    String category = aqiLevelMessageNode.path("category").asText();
    String healthEffectsStatements = aqiLevelMessageNode.path("healthEffectsStatements").asText();
    String guidance = aqiLevelMessageNode.path("guidance").asText();
    
    int minIndex = aqiLevelMessageNode.path("index").path("min").asInt();
    int maxIndex = aqiLevelMessageNode.path("index").path("max").asInt();
    Index index = new Index(minIndex, maxIndex);
    
    SpecificAQILevelMessage levelMessage = new SpecificAQILevelMessage(index, category, healthEffectsStatements, guidance);
    specificAQILevelMessages.add(levelMessage);
}

return new SpecificAQIMessage(pollutantCode, specificAQILevelMessages);
   }
 
开发者ID:ThangLeQuoc,项目名称:aqi-calculator,代码行数:21,代码来源:AQIMessageParser.java

示例2: parseJsonNode

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * 可以取出类似与fastjson JSONObject类似的一个node tree
 * path 为null时候 返回为 root json node
 * 例如:{"a":"a1","b":"b1","c":{"d":"d1","e":"e2"}}
 * 当path为null或者空时 返回jsonnode为:{"a":"a1","b":"b1","c":{"d":"d1","e":"e2"}}
 * 房path为c 返回jsonnode为: {"d":"d1","e":"e2"}
 *
 * @param json  json串
 * @param paths json key 路径path
 * @return
 */
public static JsonNode parseJsonNode(@NotNull String json, @Nullable String... paths) {
    try {
        JsonNode rootNode = objectMapper.readTree(json);
        if (!Check.isNullOrEmpty(paths)) {
            for (String pt : paths) {
                rootNode = rootNode.path(pt);
                //如果不存在
                if (rootNode.isMissingNode()) {
                    return null;
                }
            }
        }
        return rootNode;
    } catch (IOException e) {
        throw new JsonTransformException("Json获取JsonNode时出现异常。", e);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:29,代码来源:Json.java

示例3: updateDatasetDeployment

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void updateDatasetDeployment(JsonNode root)
    throws Exception {
  final JsonNode deployment = root.path("deploymentInfo");
  if (deployment.isMissingNode() || !deployment.isArray()) {
    throw new IllegalArgumentException(
        "Dataset deployment info update error, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();
  // om.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);

  for (final JsonNode deploymentInfo : deployment) {
    DeploymentRecord record = om.convertValue(deploymentInfo, DeploymentRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    DEPLOYMENT_WRITER.append(record);
  }

  // remove old info then insert new info
  DEPLOYMENT_WRITER.execute(DELETE_DATASET_DEPLOYMENT_BY_DATASET_ID, new Object[]{datasetId});
  DEPLOYMENT_WRITER.insert();
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:31,代码来源:DatasetInfoDao.java

示例4: updateDatasetCapacity

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void updateDatasetCapacity(JsonNode root)
    throws Exception {
  final JsonNode capacity = root.path("capacity");
  if (capacity.isMissingNode() || !capacity.isArray()) {
    throw new IllegalArgumentException(
        "Dataset capacity info update error, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  for (final JsonNode capacityInfo : capacity) {
    DatasetCapacityRecord record = om.convertValue(capacityInfo, DatasetCapacityRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    CAPACITY_WRITER.append(record);
  }

  // remove old info then insert new info
  CAPACITY_WRITER.execute(DELETE_DATASET_CAPACITY_BY_DATASET_ID, new Object[]{datasetId});
  CAPACITY_WRITER.insert();
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:30,代码来源:DatasetInfoDao.java

示例5: updateDatasetTags

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void updateDatasetTags(JsonNode root)
    throws Exception {
  final JsonNode tags = root.path("tags");
  if (tags.isMissingNode() || !tags.isArray()) {
    throw new IllegalArgumentException(
        "Dataset tag info update error, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  for (final JsonNode tag : tags) {
    DatasetTagRecord record = new DatasetTagRecord();
    record.setTag(tag.asText());
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    TAG_WRITER.append(record);
  }

  // remove old info then insert new info
  TAG_WRITER.execute(DELETE_DATASET_TAG_BY_DATASET_ID, new Object[]{datasetId});
  TAG_WRITER.insert();
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:29,代码来源:DatasetInfoDao.java

示例6: dataDiskStatus

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的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());
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:16,代码来源:LinuxDiskVolumeEncryptionMonitorImpl.java

示例7: updateDatasetReference

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void updateDatasetReference(JsonNode root)
    throws Exception {
  final JsonNode references = root.path("references");
  if (references.isMissingNode() || !references.isArray()) {
    throw new IllegalArgumentException(
        "Dataset reference info update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  for (final JsonNode reference : references) {
    DatasetReferenceRecord record = om.convertValue(reference, DatasetReferenceRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    REFERENCE_WRITER.append(record);
  }

  // remove old info then insert new info
  REFERENCE_WRITER.execute(DELETE_DATASET_REFERENCE_BY_DATASET_ID, new Object[]{datasetId});
  REFERENCE_WRITER.insert();
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:30,代码来源:DatasetInfoDao.java

示例8: osDiskStatus

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的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());
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:16,代码来源:LinuxDiskVolumeEncryptionMonitorImpl.java

示例9: jsonResultParse

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private JsonNode jsonResultParse(String srcJson) throws IOException {
    JsonNode root = new JsonMapper().readTree(srcJson).path("result");
    Iterator<JsonNode> uids = root.path("uids").iterator();

    if (uids.hasNext()) {
        int uid = uids.next().asInt();
        root = root.path("" + uid);
    }

    return root;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:12,代码来源:NCBIAuxiliaryManagerTest.java

示例10: queryAndCache

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * This method queries the external API and caches the movies, for the demo purpose we just query only first page
 *
 * @return - the status code of the invocation
 */
protected int queryAndCache() {

    if (this.moviesCache.isEmpty()) {

        log.info("No movies exist in cache, loading cache ..");

        UriComponentsBuilder moviesUri = UriComponentsBuilder
            .fromUriString(movieStoreProps.getApiEndpointUrl() + "/movie/popular")
            .queryParam("api_key", movieStoreProps.getApiKey());

        final URI requestUri = moviesUri.build().toUri();

        log.info("Request URI:{}", requestUri);

        ResponseEntity<String> response = restTemplate.getForEntity(requestUri, String.class);

        log.info("Response Status:{}", response.getStatusCode());

        Map<String, Movie> movieMap = new HashMap<>();

        if (200 == response.getStatusCode().value()) {
            String jsonBody = response.getBody();
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                JsonNode root = objectMapper.readTree(jsonBody);
                JsonNode results = root.path("results");
                results.elements().forEachRemaining(movieNode -> {
                    String id = movieNode.get("id").asText();
                    Movie movie = Movie.builder()
                        .id(id)
                        .overview(movieNode.get("overview").asText())
                        .popularity(movieNode.get("popularity").floatValue())
                        .posterPath("http://image.tmdb.org/t/p/w92" + movieNode.get("poster_path").asText())
                        .logoPath("http://image.tmdb.org/t/p/w45" + movieNode.get("poster_path").asText())
                        .title(movieNode.get("title").asText())
                        .price(ThreadLocalRandom.current().nextDouble(1.0, 10.0))
                        .build();
                    movieMap.put(id, movie);
                });
            } catch (IOException e) {
                log.error("Error reading response:", e);
            }

            log.debug("Got {} movies", movieMap);
            moviesCache.putAll(movieMap);
        }
        return response.getStatusCode().value();
    } else {
        log.info("Cache already loaded with movies ... will use cache");
        return 200;
    }
}
 
开发者ID:redhat-developer-demos,项目名称:popular-movie-store,代码行数:58,代码来源:MovieDBHelper.java

示例11: updateDatasetConstraint

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void updateDatasetConstraint(JsonNode root)
    throws Exception {
  final JsonNode constraints = root.path("constraints");
  if (constraints.isMissingNode() || !constraints.isArray()) {
    throw new IllegalArgumentException(
        "Dataset constraints info update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  for (final JsonNode constraint : constraints) {
    DatasetConstraintRecord record = om.convertValue(constraint, DatasetConstraintRecord.class);
    record.setDatasetId(datasetId);
    record.setDatasetUrn(urn);
    record.setModifiedTime(System.currentTimeMillis() / 1000);
    CONSTRAINT_WRITER.append(record);
  }

  // remove old info then insert new info
  CONSTRAINT_WRITER.execute(DELETE_DATASET_CONSTRAINT_BY_DATASET_ID, new Object[]{datasetId});
  CONSTRAINT_WRITER.insert();
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:30,代码来源:DatasetInfoDao.java

示例12: jsonResultParse

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private JsonNode jsonResultParse(String srcJson) throws IOException {
    JsonNode root = mapper.readTree(srcJson).path("result");
    Iterator<JsonNode> uids = root.path("uids").iterator();

    if (uids.hasNext()) {
        int uid = uids.next().asInt();
        root = root.path("" + uid);
    }

    return root;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:12,代码来源:NCBIShortVarManagerTest.java

示例13: testExtractEventMessageSuccess

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Test
@SuppressWarnings("resource")
public void testExtractEventMessageSuccess() throws Exception {

    File sampleFileMessageOnly = new File(getClass().getResource("/sample-sqs-event-message-1.json").getFile());
    String sampleFileContent = new Scanner(sampleFileMessageOnly).useDelimiter("\\Z").next();

    ObjectMapper mapper = new ObjectMapper();
    JsonNode root = mapper.readTree(sampleFileMessageOnly);

    EventMessage eventMsg = eventMessageExtractor.extractMessage(sampleFileContent);

    assertThat(eventMsg.getProgress(), equalTo(root.path("Progress").asInt()));
    assertThat(eventMsg.getAccountId(), equalTo(root.path("AccountId").asText()));
    assertThat(eventMsg.getDescription(), equalTo(root.path("Description").asText()));
    assertThat(eventMsg.getRequestId(), equalTo(root.path("RequestId").asText()));
    assertThat(eventMsg.getEndTime(), equalTo(root.path("EndTime").asText()));
    assertThat(eventMsg.getAutoScalingGroupARN(), equalTo(root.path("AutoScalingGroupARN").asText()));

    assertThat(eventMsg.getActivityId(), equalTo(root.path("ActivityId").asText()));
    assertThat(eventMsg.getStartTime(), equalTo(root.path("StartTime").asText()));
    assertThat(eventMsg.getService(), equalTo(root.path("Service").asText()));

    assertThat(eventMsg.getTime(), equalTo(root.path("Time").asText()));
    assertThat(eventMsg.getEC2InstanceId(), equalTo(root.path("EC2InstanceId").asText()));
    assertThat(eventMsg.getStatusCode(), equalTo(root.path("StatusCode").asText()));

    JsonNode details = root.path("Details");
    assertThat(eventMsg.getDetails().getSubnetID(), equalTo(details.path("Subnet ID").asText()));
    assertThat(eventMsg.getDetails().getAvailabilityZone(), equalTo(details.path("Availability Zone").asText()));

    assertThat(eventMsg.getStatusMessage(), equalTo(root.path("StatusMessage").asText()));
    assertThat(eventMsg.getAutoScalingGroupName(), equalTo(root.path("AutoScalingGroupName").asText()));
    assertThat(eventMsg.getCause(), equalTo(root.path("Cause").asText()));
    assertThat(eventMsg.getEvent(), equalTo(root.path("Event").asText()));
}
 
开发者ID:shinesolutions,项目名称:aem-orchestrator,代码行数:37,代码来源:EventMessageExtractorTest.java

示例14: decodeExtension

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public ExtFlowTypes decodeExtension(ObjectNode json) {
    if (json == null || !json.isObject()) {
        return null;
    }

    ExtTarget.Builder resultBuilder = new DefaultExtTarget.Builder();

    JsonNode jsonNodes = json.get(BgpFlowExtensionCodec.WIDE_COMM_EXT_TARGET);
    if (jsonNodes == null) {
        nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_EXT_TARGET),
                BgpFlowExtensionCodec.WIDE_COMM_EXT_TARGET + MISSING_MEMBER_MESSAGE).asText();
    }

    JsonNode array = jsonNodes.path(BgpFlowExtensionCodec.WIDE_COMM_TGT_LOCAL_SP);
    if (array == null) {
        nullIsIllegal(array, BgpFlowExtensionCodec.WIDE_COMM_TGT_LOCAL_SP + MISSING_MEMBER_MESSAGE).asText();
    }

    ExtPrefix.Builder resultBuilderPfx = parseIpArrayToPrefix(array);
    resultBuilderPfx.setType(ExtFlowTypes.ExtType.IPV4_SRC_PFX);
    resultBuilder.setLocalSpeaker(resultBuilderPfx.build());

    array = jsonNodes.path(BgpFlowExtensionCodec.WIDE_COMM_TGT_REMOTE_SP);
    if (array == null) {
        nullIsIllegal(array, BgpFlowExtensionCodec.WIDE_COMM_TGT_REMOTE_SP + MISSING_MEMBER_MESSAGE).asText();
    }

    resultBuilderPfx = parseIpArrayToPrefix(array);
    resultBuilderPfx.setType(ExtFlowTypes.ExtType.IPV4_DST_PFX);
    resultBuilder.setRemoteSpeaker(resultBuilderPfx.build());
    resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_EXT_TARGET);

    return resultBuilder.build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:DecodeBgpFlowExtnCodecHelper.java

示例15: searchEvents

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Parse JSON from Open Agenda API get by the URL
 *
 * @param is     Stream of {@link Event} from OpenAgenda
 * @param source Name of source of this data
 * @return a list of {@link Event}
 * @throws NullPointerException if is or source is null
 * @see Event
 */
default List<Event> searchEvents(InputStream is, String source) {
    Objects.requireNonNull(is);
    Objects.requireNonNull(source);
    List<Event> events = new ArrayList<>();
    ObjectMapper mapper = new ObjectMapper();
    ObjectMapper fieldMapper = new ObjectMapper();
    try {
        JsonNode root = mapper.readTree(is);
        //root
        JsonNode recordsNode = root.path("records");
        for (JsonNode knode : recordsNode) {
            JsonNode fieldsNode = knode.path("fields");
            String transform = "{\"fields\": [" + fieldsNode.toString() + "]}";
            JsonNode rootBis = fieldMapper.readTree(transform);
            JsonNode fieldsRoodNode = rootBis.path("fields");
            for (JsonNode subknode : fieldsRoodNode) {
                String latlon = subknode.path("latlon").toString();
                String title = subknode.path("title").asText();
                String description = subknode.path("description").asText() + " " + subknode.path("free_text").asText();
                String dateStart = subknode.path("date_start").asText();
                String dateEnd = subknode.path("date_end").asText();
                String city = subknode.path("city").asText();
                Event event = createEvent(latlon, title, description, dateStart, dateEnd, city, source);
                pushIfNotNullEvent(events, event);
            }
        }
    } catch (IOException e) {
        LOGGER.error("Bad json format or tree cannot be read: {}", e);
    }
    return events;
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:41,代码来源:IOpenAgenda.java


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