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


Java JsonNode.isContainerNode方法代码示例

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


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

示例1: ensureParent

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static JsonNode ensureParent(JsonNode node, JsonPointer path, String typeName) {
    /*
     * Check the parent node: it must exist and be a container (ie an array
     * or an object) for the add operation to work.
     */
    final JsonPointer parentPath = path.head();
    final JsonNode parentNode = node.at(parentPath);
    if (parentNode.isMissingNode()) {
        throw new JsonPatchException("non-existent " + typeName + " parent: " + parentPath);
    }
    if (!parentNode.isContainerNode()) {
        throw new JsonPatchException(typeName + " parent is not a container: " + parentPath +
                                     " (" + parentNode.getNodeType() + ')');
    }
    return parentNode;
}
 
开发者ID:line,项目名称:centraldogma,代码行数:17,代码来源:JsonPatchOperation.java

示例2: calculateList

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static int calculateList(JsonNode node) {
    int count = 0;
    Iterator<JsonNode> arrayIterator = node.elements();
    while (arrayIterator.hasNext()) {
        JsonNode element = arrayIterator.next();
        if (element.isArray()) {
            count += calculateList(element);
        } else if (element.isContainerNode()) {
            count += calculateDict(element);
        }
    }
    return count;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:14,代码来源:SchemaHistory.java

示例3: generateDiffs

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static void generateDiffs(final DiffProcessor processor, final JsonPointer pointer,
                                  final JsonNode source, final JsonNode target) {

    if (EQUIVALENCE.equivalent(source, target)) {
        return;
    }

    final JsonNodeType sourceType = source.getNodeType();
    final JsonNodeType targetType = target.getNodeType();

    /*
     * Node types differ: generate a replacement operation.
     */
    if (sourceType != targetType) {
        processor.valueReplaced(pointer, source, target);
        return;
    }

    /*
     * If we reach this point, it means that both nodes are the same type,
     * but are not equivalent.
     *
     * If this is not a container, generate a replace operation.
     */
    if (!source.isContainerNode()) {
        processor.valueReplaced(pointer, source, target);
        return;
    }

    /*
     * If we reach this point, both nodes are either objects or arrays;
     * delegate.
     */
    if (sourceType == JsonNodeType.OBJECT) {
        generateObjectDiffs(processor, pointer, (ObjectNode) source, (ObjectNode) target);
    } else {
        // array
        generateArrayDiffs(processor, pointer, (ArrayNode) source, (ArrayNode) target);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:41,代码来源:JsonPatch.java

示例4: doEquivalent

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@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,代码行数:41,代码来源:JsonNumEquals.java

示例5: valueAdded

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
void valueAdded(final JsonPointer pointer, final JsonNode value) {
    final JsonPatchOperation op;
    if (value.isContainerNode()) {
        // Use copy operation only for container nodes.
        final JsonPointer ptr = findUnchangedValue(value);
        op = ptr != null ? new CopyOperation(ptr, pointer)
                         : new AddOperation(pointer, value);
    } else {
        op = new AddOperation(pointer, value);
    }

    diffs.add(op);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:14,代码来源:DiffProcessor.java

示例6: isValueAProductReference

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static boolean isValueAProductReference(@Nonnull final JsonNode valueAsJsonNode) {
    if (valueAsJsonNode.isContainerNode()) {
        final JsonNode typeIdNode = valueAsJsonNode.get(REFERENCE_TYPE_ID_FIELD);
        return typeIdNode != null && Product.referenceTypeId().equals(typeIdNode.asText());
    }
    return false;
}
 
开发者ID:commercetools,项目名称:commercetools-sync-java,代码行数:8,代码来源:VariantReferenceReplacementUtils.java

示例7: elasticSearch

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static ObjectNode elasticSearch(JsonNode searchOpt, int page, int size)
{
       //Logger.debug("Entering AdvSearch.java:elasticSearch()");
	ObjectNode resultNode = Json.newObject();
	Long count = 0L;
	List<Dataset> pagedDatasets = new ArrayList<>();
	ObjectNode queryNode = Json.newObject();
	queryNode.put("from", (page-1)*size);
	queryNode.put("size", size);

	JsonNode searchNode = utils.Search.generateDatasetAdvSearchQueryString(searchOpt);

	if (searchNode != null && searchNode.isContainerNode())
	{
		queryNode.set("query", searchNode);
	}

	Logger.info(" === AdvSearchDAO::elasticSearch === The query sent to Elastic Search is: " + queryNode.toString());

	Promise<WSResponse> responsePromise = WS.url(
			Play.application().configuration().getString(
					SearchDAO.ELASTICSEARCH_DATASET_URL_KEY)).post(queryNode);
	JsonNode responseNode = responsePromise.get(1000).asJson();

	resultNode.put("page", page);
	resultNode.put("category", "Datasets");
	resultNode.put("itemsPerPage", size);

	if (responseNode != null && responseNode.isContainerNode() && responseNode.has("hits")) {
		JsonNode hitsNode = responseNode.get("hits");
		if (hitsNode != null) {
			if (hitsNode.has("total")) {
				count = hitsNode.get("total").asLong();
			}
			if (hitsNode.has("hits")) {
				JsonNode dataNode = hitsNode.get("hits");
				if (dataNode != null && dataNode.isArray()) {
					Iterator<JsonNode> arrayIterator = dataNode.elements();
					if (arrayIterator != null) {
						while (arrayIterator.hasNext()) {
							JsonNode node = arrayIterator.next();
							if (node.isContainerNode() && node.has("_id")) {
								Dataset dataset = new Dataset();
								dataset.id = node.get("_id").asLong();
								if (node.has("_source")) {
									JsonNode sourceNode = node.get("_source");
									if (sourceNode != null) {
										if (sourceNode.has("name")) {
											dataset.name = sourceNode.get("name").asText();
										}
										if (sourceNode.has("source")) {
											dataset.source = sourceNode.get("source").asText();
										}
										if (sourceNode.has("urn")) {
											dataset.urn = sourceNode.get("urn").asText();
										}
										if (sourceNode.has("schema")) {
											dataset.schema = sourceNode.get("schema").asText();
										}
									}
								}
								pagedDatasets.add(dataset);
							}
						}
					}
				}
			}
		}
	}
	resultNode.put("count", count);
	resultNode.put("totalPages", (int)Math.ceil(count/((double)size)));
	resultNode.set("data", Json.toJson(pagedDatasets));
	return resultNode;
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:75,代码来源:AdvSearchDAO.java

示例8: getDatasetPropertiesByID

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static JsonNode getDatasetPropertiesByID(int id)
{
	String properties = "";
	String source = "";
	List<Map<String, Object>> rows = null;
	JsonNode propNode = null;

	rows = getJdbcTemplate().queryForList(GET_DATASET_PROPERTIES_BY_DATASET_ID, id);

	for (Map row : rows) {
		properties = (String)row.get("properties");
		source = (String)row.get("source");
		break;
	}

	if (StringUtils.isNotBlank(properties))
	{
		try {
			propNode = Json.parse(properties);

			if (propNode != null
					&& propNode.isContainerNode()
					&& propNode.has("url")
					&& StringUtils.isNotBlank(source)
					&& source.equalsIgnoreCase("pinot"))
			{
				URL url = new URL(propNode.get("url").asText());
				BufferedReader in =
						new BufferedReader(new InputStreamReader(url.openStream()));
				String resultString = "";
				String str;

				while ((str = in.readLine()) != null) {
					resultString += str;
				}

				in.close();
				JsonNode resultNode = Json.parse(resultString);

				if (resultNode == null)
				{
					return propNode;
				}
				else{
					return resultNode;
				}
			}
		}
		catch(Exception e) {
			Logger.error("Dataset getDatasetPropertiesByID parse properties failed, id = " + id);
			Logger.error("Exception = " + e.getMessage());
		}
	}

	return propNode;
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:57,代码来源:DatasetsDAO.java

示例9: elasticSearch

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static ObjectNode elasticSearch(JsonNode searchOpt, int page, int size)
{
	ObjectNode resultNode = Json.newObject();
	Long count = 0L;
	List<Dataset> pagedDatasets = new ArrayList<>();
	ObjectNode queryNode = Json.newObject();
	queryNode.put("from", (page-1)*size);
	queryNode.put("size", size);

	JsonNode searchNode = utils.Search.generateDatasetAdvSearchQueryString(searchOpt);

	if (searchNode != null && searchNode.isContainerNode())
	{
		queryNode.set("query", searchNode);
	}
	Promise<WSResponse> responsePromise = WS.url(
			Play.application().configuration().getString(
					SearchDAO.ELASTICSEARCH_DATASET_URL_KEY)).post(queryNode);
	JsonNode responseNode = responsePromise.get(1000).asJson();

	resultNode.put("page", page);
	resultNode.put("category", "Datasets");
	resultNode.put("itemsPerPage", size);

	if (responseNode != null && responseNode.isContainerNode() && responseNode.has("hits")) {
		JsonNode hitsNode = responseNode.get("hits");
		if (hitsNode != null) {
			if (hitsNode.has("total")) {
				count = hitsNode.get("total").asLong();
			}
			if (hitsNode.has("hits")) {
				JsonNode dataNode = hitsNode.get("hits");
				if (dataNode != null && dataNode.isArray()) {
					Iterator<JsonNode> arrayIterator = dataNode.elements();
					if (arrayIterator != null) {
						while (arrayIterator.hasNext()) {
							JsonNode node = arrayIterator.next();
							if (node.isContainerNode() && node.has("_id")) {
								Dataset dataset = new Dataset();
								dataset.id = node.get("_id").asLong();
								if (node.has("_source")) {
									JsonNode sourceNode = node.get("_source");
									if (sourceNode != null) {
										if (sourceNode.has("name")) {
											dataset.name = sourceNode.get("name").asText();
										}
										if (sourceNode.has("source")) {
											dataset.source = sourceNode.get("source").asText();
										}
										if (sourceNode.has("urn")) {
											dataset.urn = sourceNode.get("urn").asText();
										}
										if (sourceNode.has("schema")) {
											dataset.schema = sourceNode.get("schema").asText();
										}
									}
								}
								pagedDatasets.add(dataset);
							}
						}
					}
				}
			}
		}
	}
	resultNode.put("count", count);
	resultNode.put("totalPages", (int)Math.ceil(count/((double)size)));
	resultNode.set("data", Json.toJson(pagedDatasets));
	return resultNode;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:71,代码来源:AdvSearchDAO.java

示例10: doHash

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
protected int doHash(final JsonNode t) {
    /*
     * If this is a numeric node, we want the same hashcode for the same
     * mathematical values. Go with double, its range is good enough for
     * 99+% of use cases.
     */
    if (t.isNumber()) {
        return Double.valueOf(t.doubleValue()).hashCode();
    }

    /*
     * If this is a primitive type (other than numbers, handled above),
     * delegate to JsonNode.
     */
    if (!t.isContainerNode()) {
        return t.hashCode();
    }

    /*
     * The following hash calculations work, yes, but they are poor at best.
     * And probably slow, too.
     *
     * TODO: try and figure out those hash classes from Guava
     */
    int ret = 0;

    /*
     * If the container is empty, just return
     */
    if (t.size() == 0) {
        return ret;
    }

    /*
     * Array
     */
    if (t.isArray()) {
        for (final JsonNode element : t) {
            ret = 31 * ret + doHash(element);
        }
        return ret;
    }

    /*
     * Not an array? An object.
     */
    final Iterator<Map.Entry<String, JsonNode>> iterator = t.fields();

    Map.Entry<String, JsonNode> entry;

    while (iterator.hasNext()) {
        entry = iterator.next();
        ret = 31 * ret + (entry.getKey().hashCode() ^ doHash(entry.getValue()));
    }

    return ret;
}
 
开发者ID:line,项目名称:centraldogma,代码行数:59,代码来源:JsonNumEquals.java


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