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


Java JsonNodeType.ARRAY属性代码示例

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


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

示例1: treeTraversalSolution

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,代码行数:30,代码来源:JSONExamples.java

示例2: parseResponse

private List<FieldValues> parseResponse(final JsonNode response) {
    if (response == null || response.get("fields") == null) {
        throw new RuntimeException("Failed to parse JSON");
    }

    final JsonNode fieldsNode = response.get("fields");

    if (fieldsNode.getNodeType() == JsonNodeType.OBJECT || fieldsNode.getNodeType() == JsonNodeType.ARRAY) {
        final List<FieldValues> output = new ArrayList<>();

        for (final JsonNode node : fieldsNode) {
            try {
                final FieldValues fieldValues = objectMapper.treeToValue(node, FieldValues.class);
                output.add(fieldValues);
            } catch (final JsonProcessingException e) {
                throw new RuntimeException("Failed to parse JSON", e);
            }
        }

        return output;
    } else {
        throw new RuntimeException("Failed to parse JSON");
    }
}
 
开发者ID:hpe-idol,项目名称:java-hod-client,代码行数:24,代码来源:GetParametricValuesServiceImpl.java

示例3: deserialize

@Override
public List<GeoCoord> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    if (JsonNodeType.ARRAY != node.getNodeType()) {
        throw new IOException("Unable to instantiate new GeoCoord Path Lists from JSON!");
    }

    List<GeoCoord> result = new ArrayList<>(node.size());
    for (int i = 0; i < node.size(); i++) {
        JsonNode p = node.get(i);
        double lon = p.get("longitude").asDouble();
        double lat = p.get("latitude").asDouble();
        result.add(new GeoCoord(lon, lat));
    }

    return result;
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:18,代码来源:GeoCoordListDeserializer.java

示例4: decodeTags

private Set<String> decodeTags(JsonNode tree, String name) {
    final JsonNode n = tree.get(name);

    if (n == null) {
        return EMPTY_TAGS;
    }

    if (n.getNodeType() != JsonNodeType.ARRAY) {
        return EMPTY_TAGS;
    }

    final List<String> tags = Lists.newArrayList();

    final Iterator<JsonNode> iter = n.elements();

    while (iter.hasNext()) {
        tags.add(iter.next().asText());
    }

    return Sets.newHashSet(tags);
}
 
开发者ID:spotify,项目名称:ffwd,代码行数:21,代码来源:JsonObjectMapperDecoder.java

示例5: getUri

public URI getUri(int index) {
	JsonNode uris = getMetadata().get("uris");
	if (uris != null) {
		try {
			if (uris.getNodeType() == JsonNodeType.STRING) {
				return new URI(uris.asText());
			} else if (uris.getNodeType() == JsonNodeType.ARRAY) {
				ArrayNode an = (ArrayNode)uris;
				return new URI(an.get(index).asText());
			}
		} catch (URISyntaxException e) {
			throw new RuntimeException("TD with malformed base uris");
		}
	} else {
		throw new RuntimeException("TD without base uris field");
	}
	// should never be reached
	throw new RuntimeException("Unexpected error while retrieving uri at index " + index);
}
 
开发者ID:thingweb,项目名称:thingweb,代码行数:19,代码来源:Thing.java

示例6: getConditions

public List<ClauseNode> getConditions() {
    List<ClauseNode> conditions = new ArrayList<ClauseNode>();

    String comparator = root.get("condition").asText();
    MatchCondition matchCondition = getMatchCondition(comparator);

    boolean not = false;
    if (root.get("not") != null) {
        not = root.get("not").asBoolean(false);
    }

    JsonNode valNode = getValue();

    if (valNode.getNodeType() == JsonNodeType.ARRAY) {
        List<Token> tokens = new ArrayList<Token>();
        for (JsonNode node : valNode) {
            tokens.add(getToken(node, matchCondition));
        }
        conditions.add(new Condition(fieldName, new Token<List<Token>>(tokens, MatchCondition.IN), not));
    } else {
        conditions.add(new Condition(fieldName, getToken(valNode, matchCondition), not));
    }
    return conditions;
}
 
开发者ID:dbasedow,项目名称:prospecter,代码行数:24,代码来源:GenericFieldHandler.java

示例7: handleIntegerField

/**
 * IntegerIndex backed fields are handled here
 *
 * @param fieldName name of the field
 * @param node      JsonNode representing the field content. This can be an array or a number
 * @return Field instance
 */
private Field handleIntegerField(String fieldName, JsonNode node) {
    List<Token> tokens = new ArrayList<Token>();
    if (node.getNodeType() == JsonNodeType.ARRAY) {
        Iterator<JsonNode> iterator = ((ArrayNode) node).elements();
        while (iterator.hasNext()) {
            JsonNode subNode = iterator.next();
            if (subNode.getNodeType() == JsonNodeType.NUMBER) {
                tokens.add(new Token<Integer>(subNode.asInt()));
            }
        }
    } else if (node.getNodeType() == JsonNodeType.NUMBER) {
        tokens.add(new Token<Integer>(node.asInt()));
    }
    return new Field(fieldName, tokens);
}
 
开发者ID:dbasedow,项目名称:prospecter,代码行数:22,代码来源:DocumentBuilder.java

示例8: deserialize

public T deserialize(String message, Websocket socket) throws MessageParseException, InvalidMessageCodeException
{
    JsonNode rootNode;
    try {
        rootNode = this.objectMapper.readTree(message);
    } catch (IOException parseException) {
        // TODO: check when this actually can happen, build a test-case for this
        throw new MessageParseException(parseException.getMessage());
    }

    if (JsonNodeType.ARRAY != rootNode.getNodeType()) {
        throw new MessageParseException("Message is no JSON-Array");
    }

    return this.deserialize(rootNode, socket);
}
 
开发者ID:fritz-gerneth,项目名称:java-wamp-server,代码行数:16,代码来源:JsonParsingConverter.java

示例9: readStringArray

private List<String> readStringArray(JsonNode rootNode, int position) throws MessageParseException
{
    JsonNode arrayNode = rootNode.get(position);
    if (null == arrayNode || JsonNodeType.ARRAY != arrayNode.getNodeType()) {
        throw new MessageParseException("Expected array at position " + position);
    }

    List<String> stringList = new ArrayList<String>();
    Iterator<JsonNode> elements = arrayNode.elements();
    int iteratorPosition = 0;
    while(elements.hasNext()) {
        JsonNode element = elements.next();
        if (JsonNodeType.STRING != element.getNodeType()) {
            throw new MessageParseException("Array-Item at position " + iteratorPosition + " is no string");
        }
        String stringifiedElement = element.asText();
        if (0 == stringifiedElement.length()) {
            throw new MessageParseException("Array-Item as position " + iteratorPosition + " may not be empty");
        }
        stringList.add(stringifiedElement);
        iteratorPosition++;
    }

    return stringList;
}
 
开发者ID:fritz-gerneth,项目名称:java-wamp-server,代码行数:25,代码来源:PublishMessageConverter.java

示例10: doEquivalent

@Override
protected boolean doEquivalent(final JsonNode a, final JsonNode b) {
    /*
     * If both are numbers, delegate to the helper method
     */
    if (a.isNumber() && b.isNumber()) {
        return numEquals(a, b);
    }

    final JsonNodeType typeA = a.getNodeType();
    final JsonNodeType typeB = b.getNodeType();

    /*
     * If they are of different types, no dice
     */
    if (typeA != typeB) {
        return false;
    }

    /*
     * For all other primitive types than numbers, trust JsonNode
     */
    if (!a.isContainerNode()) {
        return a.equals(b);
    }

    /*
     * OK, so they are containers (either both arrays or objects due to the
     * test on types above). They are obviously not equal if they do not
     * have the same number of elements/members.
     */
    if (a.size() != b.size()) {
        return false;
    }

    /*
     * Delegate to the appropriate method according to their type.
     */
    return typeA == JsonNodeType.ARRAY ? arrayEquals(a, b) : objectEquals(a, b);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:40,代码来源:JsonNumEquals.java

示例11: deserialize

@Override
public CiListRequest deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);
    if (node.getNodeType() == JsonNodeType.ARRAY) {
        return new CiListRequest(getIds(node));
    }
    else {
        JsonNode attrProps = node.get("attrProps");
        JsonNode altNsTag = node.get("includeAltNs");
        return new CiListRequest(getIds(node.get("ids")),
                attrProps == null ? null :attrProps.asText(),
                altNsTag == null ? null : altNsTag.asText());
    }
}
 
开发者ID:oneops,项目名称:oneops,代码行数:14,代码来源:CmRestController.java

示例12: deserialize

@Override
public List<List<GeoCoord>> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = jp.getCodec();
    JsonNode node = codec.readTree(jp);

    if (JsonNodeType.ARRAY != node.getNodeType()) {
        throw new IOException("Unable to instantiate new GeoCoord Path Lists from JSON!");
    }

    int nodeSize = node.size();
    List<List<GeoCoord>> result = new ArrayList<>(nodeSize);

    for (int i = 0; i < nodeSize; i++) {

        JsonNode points = node.get(i);
        int pointsSize = points.size();
        List<GeoCoord> path = new ArrayList<>(pointsSize);

        for (int j = 0; j < pointsSize; j++) {
            JsonNode p = points.get(j);
            double x = p.get(0).asDouble();
            double y = p.get(1).asDouble();
            path.add(new GeoCoord(x, y));
        }
        result.add(path);

    }

    return result;
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:30,代码来源:ListGeoCoordListDeserializer.java

示例13: createSchemaByJsonNode

private static ObjectNode createSchemaByJsonNode(JsonNode node) {
	   ObjectNode resultNodeNew = mapper.getNodeFactory().objectNode(); 
	  if (node.getNodeType() == JsonNodeType.OBJECT) {
		  ObjectNode objResult  = leafNodes(node);
		  resultNodeNew.put(TYPE, OBJECT);
		  resultNodeNew.set(PROPERTIES, objResult);
		} else if (node.getNodeType() == JsonNodeType.ARRAY) {				
			ObjectNode items = identifyAndProcessArrayNode(node);
			resultNodeNew =  items;
		}
	return resultNodeNew;
}
 
开发者ID:pegasystems,项目名称:api2swagger,代码行数:12,代码来源:JsonSchemaGeneratorUtils.java

示例14: createModelByJsonNode

private void createModelByJsonNode(JsonNode node, String apiName, ModelBuilder rootModelBuilder){
	if (node.getNodeType() == JsonNodeType.OBJECT) {
		createObjectModel(node, rootModelBuilder, apiName);
		models.put(apiName, rootModelBuilder);
	} else if (node.getNodeType() == JsonNodeType.ARRAY) {
		ArrayPropertyBuilder arrayPropertyBuilder = rootModelBuilder.withArrayProperty(apiName);
		createArrayModel(node, arrayPropertyBuilder, apiName + "-item");
		models.put(apiName, rootModelBuilder);
	}		
}
 
开发者ID:pegasystems,项目名称:api2swagger,代码行数:10,代码来源:SwaggerModelGenerator.java

示例15: createObjectModel

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,代码行数:28,代码来源:SwaggerModelGenerator.java


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