當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。