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


Java JsonNode.fieldNames方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-for-Data-Science,代码行数:31,代码来源:JSONExamples.java

示例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 + "'!");
        }
    }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:24,代码来源:DataValidator.java

示例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;
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:27,代码来源:MaprElasticSearchServiceBuilder.java

示例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);
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:19,代码来源:ShapeModelReflector.java

示例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();
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:24,代码来源:DefinitionParser.java

示例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;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:29,代码来源:CasOAuthWrapperClient.java

示例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;
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:SchemaGenerator.java

示例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());
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Jackson2Annotator.java

示例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;
}
 
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:22,代码来源:JsonHelper.java

示例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);				
		}
	}		
}
 
开发者ID:pegasystems,项目名称:api2swagger,代码行数:29,代码来源:SwaggerModelGenerator.java

示例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));
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:13,代码来源:JsonPatch.java

示例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();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:HostsWebResource.java

示例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);
}
 
开发者ID:zezutom,项目名称:schematic,代码行数:28,代码来源:BaseJsonNodeParser.java

示例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;
    }
}
 
开发者ID:zezutom,项目名称:schematic,代码行数:40,代码来源:ObjectParser.java

示例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;
}
 
开发者ID:pegasystems,项目名称:api2swagger,代码行数:6,代码来源:JsonSchemaGeneratorUtils.java


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