本文整理了Java中com.fasterxml.jackson.databind.JsonNode.findParents()
方法的一些代码示例,展示了JsonNode.findParents()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.findParents()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:findParents
[英]Method for finding a JSON Object that contains specified field, within this node or its descendants. If no matching field is found in this node or its descendants, returns null.
[中]方法,用于在此节点或其子节点内查找包含指定字段的JSON对象。如果在此节点或其子节点中未找到匹配字段,则返回null。
代码示例来源:origin: redisson/redisson
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
}
return foundSoFar;
}
代码示例来源:origin: redisson/redisson
/**
* Method for finding a JSON Object that contains specified field,
* within this node or its descendants.
* If no matching field is found in this node or its descendants, returns null.
*
* @param fieldName Name of field to look for
*
* @return Value of first matching node found, if any; null if none
*/
public final List<JsonNode> findParents(String fieldName)
{
List<JsonNode> result = findParents(fieldName, null);
if (result == null) {
return Collections.emptyList();
}
return result;
}
代码示例来源:origin: redisson/redisson
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
if (foundSoFar == null) {
foundSoFar = new ArrayList<JsonNode>();
}
foundSoFar.add(this);
} else { // only add children if parent not added
foundSoFar = entry.getValue()
.findParents(fieldName, foundSoFar);
}
}
return foundSoFar;
}
代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
if (_children != null) {
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
}
}
return foundSoFar;
}
代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
}
return foundSoFar;
}
代码示例来源:origin: hstaudacher/osgi-jax-rs-connector
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
}
return foundSoFar;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
if (_children != null) {
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
}
}
return foundSoFar;
}
代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
}
return foundSoFar;
}
代码示例来源:origin: Nextdoor/bender
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
for (JsonNode node : _children) {
foundSoFar = node.findParents(fieldName, foundSoFar);
}
return foundSoFar;
}
代码示例来源:origin: stackoverflow.com
JsonNode root = mapper.readTree(SCHEMA);
List<JsonNode> required = root.findParents("required");
for (JsonNode node: required) {
Object prettyOutput = mapper.readValue(node, Object.class);
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(prettyOutput));
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
private void productIdInLineItems(final JsonNode resourceDraftNode) {
final JsonNode lineItems = resourceDraftNode.get("lineItems");
if (lineItems != null && lineItems.isArray()) {
final List<JsonNode> parents = resourceDraftNode.findParents(PRODUCT_ID_FIELD_NAME);
parents.forEach(node -> {
final String newId = keyToIdMap.get(node.get(PRODUCT_ID_FIELD_NAME).asText());
((ObjectNode) node).replace(PRODUCT_ID_FIELD_NAME, new TextNode(newId));
});
}
}
代码示例来源:origin: com.atlassian.oai/swagger-request-validator-core
private static void setupNullableEnums(final JsonNode schemaObject) {
// If the node is marked as nullable, and this node is an enum, then we
// need to extend the set of enumerated values to include null, so that
// it will be properly handled by the JSON-schema validation routine.
schemaObject
.findParents(ENUM_KEY)
.stream()
.filter(jsonNode -> jsonNode.path(NULLABLE_KEY).asBoolean(false))
.filter(jsonNode -> !alreadySupportsNullEnum(jsonNode))
.forEach(jsonNode -> ((ArrayNode) jsonNode.get(ENUM_KEY)).addNull());
}
代码示例来源:origin: org.symphonyoss.symphony/messageml
/**
* Verify that JSON media node contains valid table payload.
*/
private void validateMedia(JsonNode data) throws InvalidInputException {
for (JsonNode node : data.findParents(INDEX)) {
JsonNode text = node.path(TEXT);
if (!text.isMissingNode() && (!text.isArray() || !text.get(0).isArray())) {
throw new InvalidInputException(String.format("Invalid table payload: %s (index: %s)", text.asText(), node.get(INDEX)));
}
}
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-test-lib
private void productIdInLineItems(final JsonNode resourceDraftNode) {
final JsonNode lineItems = resourceDraftNode.get("lineItems");
if (lineItems != null && lineItems.isArray()) {
final List<JsonNode> parents = resourceDraftNode.findParents(PRODUCT_ID_FIELD_NAME);
parents.forEach(node -> {
final String newId = keyToIdMap.get(node.get(PRODUCT_ID_FIELD_NAME).asText());
((ObjectNode) node).replace(PRODUCT_ID_FIELD_NAME, new TextNode(newId));
});
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
private void customerIdInOrders(final JsonNode resourceDraftNode) {
final String fieldName = "customerId";
final List<JsonNode> nodesContainingCustomerId = resourceDraftNode.findParents(fieldName);
nodesContainingCustomerId.forEach(node -> {
if (node != null && node.isObject()) {
final String newId = keyToIdMap.get(node.get(fieldName).asText());
((ObjectNode) node).replace(fieldName, new TextNode(newId));
}
});
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-test-lib
private void customerIdInOrders(final JsonNode resourceDraftNode) {
final String fieldName = "customerId";
final List<JsonNode> nodesContainingCustomerId = resourceDraftNode.findParents(fieldName);
nodesContainingCustomerId.forEach(node -> {
if (node != null && node.isObject()) {
final String newId = keyToIdMap.get(node.get(fieldName).asText());
((ObjectNode) node).replace(fieldName, new TextNode(newId));
}
});
}
代码示例来源:origin: Nextdoor/bender
private static void modifyNode(JsonNode schema) {
List<JsonNode> parents = schema.findParents("items");
for (JsonNode parent : parents) {
if (parent.hasNonNull("type") && parent.get("type").asText().equals("array")) {
if (parent.get("items").hasNonNull("oneOf")) {
((ObjectNode) parent).put("anyOf", parent.get("items").get("oneOf"));
((ObjectNode) parent).remove("items");
}
}
}
}
}
代码示例来源:origin: io.sphere.sdk.jvm/sphere-test-lib
private void references(final JsonNode resourceDraftNode) {
resourceDraftNode.findParents("typeId")
.stream()
.filter(node -> node.isObject())
.map(node -> (ObjectNode)node)
.filter(node -> node.size() == 2 && node.has("id"))
.forEach(node -> {
final String id = keyToIdMap.get(node.get("id").asText());
node.replace("id", new TextNode(id));
});
}
}
代码示例来源:origin: commercetools/commercetools-jvm-sdk
private void references(final JsonNode resourceDraftNode) {
resourceDraftNode.findParents("typeId")
.stream()
.filter(node -> node.isObject())
.map(node -> (ObjectNode)node)
.filter(node -> node.size() == 2 && node.has("id"))
.forEach(node -> {
final String id = keyToIdMap.get(node.get("id").asText());
node.replace("id", new TextNode(id));
});
}
}
代码示例来源:origin: dswarm/dswarm
public static void transformIdToUuidInJson(final JsonNode json) {
final List<JsonNode> matches = json.findParents(ID_FIELD_NAME);
for (final JsonNode match : matches) {
final long id = match.get(ID_FIELD_NAME).asLong();
((ObjectNode) match).remove(ID_FIELD_NAME);
((ObjectNode) match).put(UUID_FIELD_NAME, "" + id);
}
}
内容来源于网络,如有侵权,请联系作者删除!