本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.fieldNames方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.fieldNames方法的具体用法?Java JsonNode.fieldNames怎么用?Java JsonNode.fieldNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.fieldNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: treeTraversalSolution
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public void treeTraversalSolution() {
try {
ObjectMapper mapper = new ObjectMapper();
// use the ObjectMapper to read the json string and create a tree
JsonNode node = mapper.readTree(new File("Persons.json"));
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
JsonNode personsNode = node.get("persons");
Iterator<JsonNode> elements = personsNode.iterator();
while (elements.hasNext()) {
JsonNode element = elements.next();
JsonNodeType nodeType = element.getNodeType();
if (nodeType == JsonNodeType.STRING) {
out.println("Group: " + element.textValue());
}
if (nodeType == JsonNodeType.ARRAY) {
Iterator<JsonNode> fields = element.iterator();
while (fields.hasNext()) {
parsePerson(fields.next());
}
}
}
fieldNames.next();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例2: validateJsonStructure
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
protected static void validateJsonStructure(JsonNode expectedNode, JsonNode actualNode) {
Set<String> expectedFields = new HashSet<>();
Iterator<String> fieldsIterator = expectedNode.fieldNames();
while (fieldsIterator.hasNext()) {
expectedFields.add(fieldsIterator.next());
}
Set<String> actualFields = new HashSet<>();
fieldsIterator = actualNode.fieldNames();
while (fieldsIterator.hasNext()) {
actualFields.add(fieldsIterator.next());
}
if (!expectedFields.containsAll(actualFields) || !actualFields.containsAll(expectedFields)) {
throw new DataValidationException("Provided json structure is different from stored one '" + actualNode + "'!");
}
for (String field : actualFields) {
if (!actualNode.get(field).isTextual()) {
throw new DataValidationException("Provided json structure can't contain non-text values '" + actualNode + "'!");
}
}
}
示例3: copyOnlyAllowedFields
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Only specified fields will be sent to the ElasticSearch.
*
* @param original all the changes.
* @return changes for the specified fields.
*/
private JsonNode copyOnlyAllowedFields(JsonNode original) {
ObjectNode allowed = null;
Iterator<String> fieldNamesIterator = original.fieldNames();
while (fieldNamesIterator.hasNext()) {
String fieldName = fieldNamesIterator.next();
if (!fields.contains(fieldName)) {
continue;
}
if (allowed == null) {
allowed = mapper.createObjectNode();
}
allowed.set(fieldName, original.get(fieldName));
}
return allowed;
}
示例4: initializeFields
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void initializeFields(ShapeModel structureShape, JsonNode input,
Object shapeObject) throws Exception {
Iterator<String> fieldNames = input.fieldNames();
while (fieldNames.hasNext()) {
String memberName = fieldNames.next();
MemberModel memberModel = structureShape.getMemberByC2jName(memberName);
if (memberModel == null) {
throw new IllegalArgumentException("Member " + memberName + " was not found in the " +
structureShape.getC2jName() + " shape.");
}
final Object toSet = getMemberValue(input.get(memberName), memberModel);
if (toSet != null) {
Method setter = getMemberSetter(shapeObject.getClass(), memberModel);
setter.setAccessible(true);
setter.invoke(shapeObject, toSet);
}
}
}
示例5: checkForInvalidMongoKeys
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private String checkForInvalidMongoKeys ( JsonNode definitionNode, String location ) {
// TODO Auto-generated method stub
StringBuffer resultsBuf = new StringBuffer( "" );
Iterator<String> names = definitionNode.fieldNames();
while (names.hasNext()) {
String name = names.next();
// if ( logger.isDebugEnabled() )
// logger.debug("key: " + name + " location: " + location);
JsonNode fieldValue = definitionNode.get( name );
if ( fieldValue.isObject() ) {
resultsBuf.append( checkForInvalidMongoKeys( fieldValue, location + "," + name ) );
} else if ( name.contains( "." ) ) {
resultsBuf.append( CSAP.CONFIG_PARSE_WARN + " - \".\" should not appear in: \"" + name
+ "\" in definition file: " + location + "\n" );
}
}
// resultsBuf.append(CONFIG_PARSE_WARN +
// " - invalid key in definition file: " + fileName + "\n");
return resultsBuf.toString();
}
示例6: extractUserProfile
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
protected CasOAuthWrapperProfile extractUserProfile(final String body) throws HttpAction {
final CasOAuthWrapperProfile userProfile = new CasOAuthWrapperProfile();
JsonNode json = JsonHelper.getFirstNode(body);
if (json != null) {
userProfile.setId(JsonHelper.getElement(json, "id"));
json = json.get("attributes");
if (json != null) {
// CAS <= v4.2
if (json instanceof ArrayNode) {
final Iterator<JsonNode> nodes = json.iterator();
while (nodes.hasNext()) {
json = nodes.next();
final String attribute = json.fieldNames().next();
userProfile.addAttribute(attribute, JsonHelper.getElement(json, attribute));
}
// CAS v5
} else if (json instanceof ObjectNode) {
final Iterator<String> keys = json.fieldNames();
while (keys.hasNext()) {
final String key = keys.next();
userProfile.addAttribute(key, JsonHelper.getElement(json, key));
}
}
}
}
return userProfile;
}
示例7: objectSchema
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private ObjectNode objectSchema(JsonNode exampleObject) {
ObjectNode schema = this.objectMapper.createObjectNode();
schema.put("type", "object");
ObjectNode properties = this.objectMapper.createObjectNode();
for (Iterator<String> iter = exampleObject.fieldNames(); iter.hasNext();) {
String property = iter.next();
properties.set(property, schemaFromExample(exampleObject.get(property)));
}
schema.set("properties", properties);
return schema;
}
示例8: propertyOrder
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) {
JAnnotationArrayMember annotationValue = clazz.annotate(JsonPropertyOrder.class).paramArray("value");
for (Iterator<String> properties = propertiesNode.fieldNames(); properties.hasNext();) {
annotationValue.param(properties.next());
}
}
示例9: getNode
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* returns the object associated with the given key, ignoring case
* if object cannot be found, returns null
*
* @param node
* @param key
* @return value for given key
*/
public static JsonNode getNode(JsonNode node, String key) {
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
String fieldName = fieldNames.next();
if (fieldName.equalsIgnoreCase(key)) {
return node.get(fieldName);
}
}
return null;
}
示例10: createObjectModel
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void createObjectModel(JsonNode node, ModelBuilder modelBuilder, String apiName) {
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
String field = fieldNames.next();
JsonNode leafNode = node.get(field);
if (leafNode.getNodeType() == JsonNodeType.NUMBER) {
if (leafNode.isInt() || leafNode.isLong()) {
modelBuilder.withIntegerPropertyNamed(field).withExample(leafNode.asLong());
} else if (leafNode.isFloat() || leafNode.isDouble()) {
modelBuilder.withNumberPropertyNamed(field).withExample(leafNode.asDouble());
}
} else if (leafNode.getNodeType() == JsonNodeType.BOOLEAN) {
modelBuilder.withBooleanPropertyNamed(field).withExample(leafNode.asBoolean());
} else if (leafNode.getNodeType() == JsonNodeType.STRING) {
modelBuilder.withStringPropertyNamed(field).withExample(leafNode.asText());
} else if (leafNode.getNodeType() == JsonNodeType.OBJECT) {
String refName = apiName+"-"+field;
modelBuilder.withReferencePropertyNamed(field).withReferenceTo(refName);
ModelBuilder objModelBuilder = new ModelBuilder();
createObjectModel(leafNode, objModelBuilder, refName);
models.put(refName, objModelBuilder);
}else if(leafNode.getNodeType() == JsonNodeType.ARRAY){
createArrayModel(leafNode, modelBuilder.withArrayProperty(field), apiName+"-"+field);
}
}
}
示例11: computeUnchangedObject
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static void computeUnchangedObject(final Map<JsonPointer, JsonNode> ret, final JsonPointer pointer,
final JsonNode source, final JsonNode target) {
final Iterator<String> sourceFields = source.fieldNames();
while (sourceFields.hasNext()) {
final String name = sourceFields.next();
if (!target.has(name)) {
continue;
}
computeUnchanged(ret, pointer.append(JsonPointer.valueOf('/' + name)),
source.get(name), target.get(name));
}
}
示例12: annotations
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Produces annotations from specified JsonNode. Copied from the ConfigProvider
* class for use in the POST method.
*
* @param node node to be annotated
* @return SparseAnnotations object with information about node
*/
private SparseAnnotations annotations(JsonNode node) {
if (node == null) {
return DefaultAnnotations.EMPTY;
}
DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
Iterator<String> it = node.fieldNames();
while (it.hasNext()) {
String k = it.next();
builder.set(k, node.get(k).asText());
}
return builder.build();
}
示例13: parse
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public N parse(String nodeName, JsonNode jsonNode) {
if (jsonNode == null) return null;
// Iterate over node's properties
Iterator<String> fieldNameIterator = jsonNode.fieldNames();
while (fieldNameIterator.hasNext()) {
String fieldName = fieldNameIterator.next();
if (isProperty(fieldName)) {
P property = getProperty(fieldName);
JsonNode propertyNode = jsonNode.get(fieldName);
if (property == null || propertyNode == null) continue;
parseProperty(generator, property, propertyNode);
} else if (isCombinationType(fieldName)) {
JsonNode combinationNode = jsonNode.get(fieldName);
if (combinationNode != null && combinationNode.isArray()) {
JsonSchemaCombinationType type = JsonSchemaCombinationType.get(fieldName);
List<JsonNode> combinationNodes = new ArrayList<>();
Iterator<JsonNode> combinationNodeIterator = combinationNode.elements();
while (combinationNodeIterator.hasNext()) {
combinationNodes.add(combinationNodeIterator.next());
}
generator.combine(type, combinationNodes);
}
}
}
return getNode(nodeName, generator);
}
示例14: parseProperty
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
void parseProperty(@NotNull ObjectGenerator generator, @NotNull JsonObjectProperty property, @NotNull JsonNode jsonNode) {
switch (property) {
case PROPERTIES:
Iterator<String> fieldNameIterator = jsonNode.fieldNames();
while (fieldNameIterator.hasNext()) {
String fieldName = fieldNameIterator.next();
generator.addProperty(fieldName, resolveGenerator(jsonNode.get(fieldName)));
}
break;
case ADDITIONAL_PROPERTIES:
if (jsonNode.isBoolean()) {
generator.setAdditionalPropertiesAllowed(jsonNode.booleanValue());
} else {
JsonDataType dataType = JsonUtil.getDataType(jsonNode);
if (dataType != null) {
JsonNodeParser parser = parserFactory.getInstance(jsonNode);
if (parser != null) {
Node node = parser.parse(jsonNode);
if (node != null) {
generator.addAdditionalGenerator(node.getValueGenerator());
}
}
}
}
break;
case MIN_PROPERTIES:
generator.setMin(jsonNode.intValue());
break;
case MAX_PROPERTIES:
generator.setMax(jsonNode.intValue());
break;
case REQUIRED:
for (JsonNode requiredNode : jsonNode) {
generator.addRequiredProperty(requiredNode.textValue());
}
break;
}
}
示例15: leafNodes
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static ObjectNode leafNodes(JsonNode intermediateNode) {
Iterator<String> fieldNames = intermediateNode.fieldNames();
ObjectNode resultNode = traverseLeafNodes(intermediateNode, fieldNames);
return resultNode;
}