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


Java JsonParser.nextFieldName方法代码示例

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


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

示例1: deserialize

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
  Object result = createResult();
  for (String fieldName = p.nextFieldName(); fieldName != null; fieldName = p.nextFieldName()) {
    // p实际是ProtobufParser,其内部是可以直接取到proto field的,理论上可以根据id来索引
    // 可是field默认没暴露出来,所以,直接用name索引了
    ReaderHelpData helpData = readerHelpDataMap.get(fieldName);
    if (helpData == null) {
      continue;
    }

    JsonToken t = p.nextToken();
    // Note: must handle null explicitly here; value deserializers won't
    Object value = null;
    if (t == JsonToken.VALUE_NULL) {
      value = helpData.getDeser().getNullValue(ctxt);
    } else {
      value = helpData.getDeser().deserialize(p, ctxt);
    }

    result = updateResult(result, value, helpData);
  }

  return result;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:26,代码来源:AbstractDeserializer.java

示例2: deserialize

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public OAuthToken deserialize(final JsonParser p, final DeserializationContext ctxt)
    throws IOException, JsonProcessingException {
    final Map<String, String> values = new HashMap<>();
    String fieldName;
    while ((fieldName = p.nextFieldName()) != null) {
        final String nextValue = p.nextTextValue();
        values.put(fieldName, nextValue);
    }

    return new OAuthToken(values.get("value"), values.get("secret"));
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:13,代码来源:CredentialModule.java

示例3: testJacksonParsing

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Test
public void testJacksonParsing() throws IOException {
    ObjectMapper mapper = IndexV1Updater.getObjectMapperInstance(FAKE_REPO_ID);
    // the app ignores all unknown fields when complete, do not ignore during dev to catch mistakes
    mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    JsonFactory f = mapper.getFactory();
    JsonParser parser = f.createParser(TestUtils.copyResourceToTempFile("guardianproject_index-v1.json"));

    Repo repo = null;
    App[] apps = null;
    Map<String, String[]> requests = null;
    Map<String, List<Apk>> packages = null;

    parser.nextToken(); // go into the main object block
    while (true) {
        String fieldName = parser.nextFieldName();
        if (fieldName == null) {
            break;
        }
        switch (fieldName) {
            case "repo":
                repo = parseRepo(mapper, parser);
                break;
            case "requests":
                requests = parseRequests(mapper, parser);
                break;
            case "apps":
                apps = parseApps(mapper, parser);
                break;
            case "packages":
                packages = parsePackages(mapper, parser);
                break;
        }
    }
    parser.close(); // ensure resources get cleaned up timely and properly

    RepoDetails indexV0Details = getFromFile("guardianproject_index.xml",
            Repo.PUSH_REQUEST_ACCEPT_ALWAYS);
    indexV0Details.apps.size();

    assertEquals(indexV0Details.apps.size(), apps.length);
    assertEquals(apps.length, packages.size());

    int totalApks = 0;
    for (String packageName : packages.keySet()) {
        totalApks += packages.get(packageName).size();
    }
    assertEquals(totalApks, indexV0Details.apks.size());

    assertEquals(indexV0Details.icon, repo.icon);
    assertEquals(indexV0Details.timestamp, repo.timestamp / 1000); // V1 is in millis
    assertEquals(indexV0Details.name, repo.name);
    assertArrayEquals(indexV0Details.mirrors, repo.mirrors);

    ArrayList<String> installRequests = new ArrayList<>();
    for (RepoPushRequest repoPushRequest : indexV0Details.repoPushRequestList) {
        if ("install".equals(repoPushRequest.request)) {
            installRequests.add(repoPushRequest.packageName);
        }
    }
    assertArrayEquals(installRequests.toArray(), requests.get("install"));
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:63,代码来源:IndexV1UpdaterTest.java


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