本文整理汇总了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;
}
示例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"));
}
示例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"));
}