com.fasterxml.jackson.databind.node.ObjectNode.fieldNames()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中com.fasterxml.jackson.databind.node.ObjectNode.fieldNames()方法的一些代码示例,展示了ObjectNode.fieldNames()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectNode.fieldNames()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.node.ObjectNode
类名称:ObjectNode
方法名:fieldNames

ObjectNode.fieldNames介绍

暂无

代码示例

代码示例来源:origin: embulk/embulk

@Override
public boolean isEmpty() {
  return !data.fieldNames().hasNext();
}

代码示例来源:origin: embulk/embulk

@Override
public List<String> getAttributeNames() {
  return ImmutableList.copyOf(data.fieldNames());
}

代码示例来源:origin: json-path/JsonPath

@Override
public Collection<String> getPropertyKeys(Object obj) {
  List<String> keys = new ArrayList<String>();
  Iterator<String> iter = toJsonObject(obj).fieldNames();
  while (iter.hasNext()){
    keys.add(iter.next());
  }
  return keys;
}

代码示例来源:origin: bootique/bootique

protected JsonNode mergeObjects(JsonNode target, JsonNode source) {
  ObjectNode targetObject = (ObjectNode) target;
  ObjectNode srcObject = (ObjectNode) source;
  Iterator<String> fieldNames = srcObject.fieldNames();
  while (fieldNames.hasNext()) {
    String fieldName = fieldNames.next();
    JsonNode srcChild = srcObject.get(fieldName);
    JsonNode targetChild = targetObject.get(fieldName);
    targetObject.replace(fieldName, apply(targetChild, srcChild));
  }
  return target;
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

private ObjectNode mergeObjectNodes(ObjectNode targetNode, ObjectNode updateNode) {
  Iterator<String> fieldNames = updateNode.fieldNames();
  while (fieldNames.hasNext()) {
    String fieldName = fieldNames.next();
    JsonNode targetValue = targetNode.get(fieldName);
    JsonNode updateValue = updateNode.get(fieldName);
    if (targetValue == null) {
      // Target node doesn't have this field from update node: just add it
      targetNode.set(fieldName, updateValue);
    } else {
      // Both nodes have the same field: merge the values
      if (targetValue.isObject() && updateValue.isObject()) {
        // Both values are objects: recurse
        targetNode.set(fieldName, mergeObjectNodes((ObjectNode) targetValue, (ObjectNode) updateValue));
      } else if (targetValue.isArray() && updateValue.isArray()) {
        // Both values are arrays: concatenate them to be merged later
        ((ArrayNode) targetValue).addAll((ArrayNode) updateValue);
      } else {
        // Values have different types: use the one from the update node
        targetNode.set(fieldName, updateValue);
      }
    }
  }
  return targetNode;
}

代码示例来源:origin: swagger-api/swagger-core

@Override
  public Paths deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    Paths result = new Paths();
    JsonNode node = jp.getCodec().readTree(jp);
    ObjectNode objectNode = (ObjectNode)node;
    Map<String, Object> extensions = new LinkedHashMap<>();
    for (Iterator<String> it = objectNode.fieldNames(); it.hasNext(); ) {
      String childName = it.next();
      JsonNode child = objectNode.get(childName);
      // if name start with `x-` consider it an extesion
      if (childName.startsWith("x-")) {
        extensions.put(childName, Json.mapper().convertValue(child, Object.class));
      } else {
        result.put(childName, Json.mapper().convertValue(child, PathItem.class));
      }
    }
    if (!extensions.isEmpty()) {
      result.setExtensions(extensions);
    }
    return result;
  }
}

代码示例来源:origin: swagger-api/swagger-core

@Override
  public ApiResponses deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    ApiResponses result = new ApiResponses();
    JsonNode node = jp.getCodec().readTree(jp);
    ObjectNode objectNode = (ObjectNode)node;
    Map<String, Object> extensions = new LinkedHashMap<>();
    for (Iterator<String> it = objectNode.fieldNames(); it.hasNext(); ) {
      String childName = it.next();
      JsonNode child = objectNode.get(childName);
      // if name start with `x-` consider it an extesion
      if (childName.startsWith("x-")) {
        extensions.put(childName, Json.mapper().convertValue(child, Object.class));
      } else {
        result.put(childName, Json.mapper().convertValue(child, ApiResponse.class));
      }
    }
    if (!extensions.isEmpty()) {
      result.setExtensions(extensions);
    }
    return result;
  }
}

代码示例来源:origin: swagger-api/swagger-core

@Override
  public Callback deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    Callback result = new Callback();
    JsonNode node = jp.getCodec().readTree(jp);
    ObjectNode objectNode = (ObjectNode)node;
    Map<String, Object> extensions = new LinkedHashMap<>();
    for (Iterator<String> it = objectNode.fieldNames(); it.hasNext(); ) {
      String childName = it.next();
      JsonNode child = objectNode.get(childName);
      // if name start with `x-` consider it an extesion
      if (childName.startsWith("x-")) {
        extensions.put(childName, Json.mapper().convertValue(child, Object.class));
      } else if (childName.equals("$ref")) {
        result.$ref(child.asText());
      } else {
        result.put(childName, Json.mapper().convertValue(child, PathItem.class));
      }
    }
    if (!extensions.isEmpty()) {
      result.setExtensions(extensions);
    }
    return result;
  }
}

代码示例来源:origin: aws/aws-sdk-java

obj.fieldNames().forEachRemaining(m -> {
  if (!excludes.contains(m)) {
    modified.set(m, obj.get(m));

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public Collection<String> getPropertyKeys(Object obj) {
  List<String> keys = new ArrayList<String>();
  Iterator<String> iter = toJsonObject(obj).fieldNames();
  while (iter.hasNext()){
    keys.add(iter.next());
  }
  return keys;
}

代码示例来源:origin: HubSpot/Singularity

private static void merge(ObjectNode to, ObjectNode from) {
    Iterator<String> newFieldNames = from.fieldNames();

    while (newFieldNames.hasNext()) {
      String newFieldName = newFieldNames.next();
      JsonNode oldVal = to.get(newFieldName);
      JsonNode newVal = from.get(newFieldName);

      if (oldVal == null || oldVal.isNull()) {
        to.set(newFieldName, newVal);
      } else if (oldVal.isArray() && newVal.isArray()) {
        ((ArrayNode) oldVal).removeAll();
        ((ArrayNode) oldVal).addAll((ArrayNode) newVal);
      } else if (oldVal.isObject() && newVal.isObject()) {
        merge((ObjectNode) oldVal, (ObjectNode) newVal);
      } else if (!(newVal == null || newVal.isNull())) {
        to.set(newFieldName, newVal);
      }
    }
  }
}

代码示例来源:origin: opensourceBIM/BIMserver

private void parseDefines(Query query, ObjectNode jsonNode) throws QueryException {
  Iterator<String> fieldNames = jsonNode.fieldNames();
  // First pass, get all the name and create stub includes, using two passing to allow the usage of includes defined later in the structure
  while (fieldNames.hasNext()) {
    String fieldName = fieldNames.next();
    JsonNode defineNode = jsonNode.get(fieldName);
    if (defineNode instanceof ObjectNode) {
      Include include = new Include(packageMetaData);
      query.addDefine(fieldName, include);
    } else {
      throw new QueryException("\"defines\"[" + fieldName + "] must be of type object");
    }
  }
  // Second pass, actually construct the includes
  fieldNames = jsonNode.fieldNames();
  while (fieldNames.hasNext()) {
    String fieldName = fieldNames.next();
    JsonNode defineNode = jsonNode.get(fieldName);
    ObjectNode define = (ObjectNode)defineNode;
    parseInclude(query, define, query.getDefine(fieldName), null);
  }
}

代码示例来源:origin: spring-projects/spring-data-rest

if (!objectNode.fieldNames().hasNext()) {
  return;
if (!objectNode.fieldNames().hasNext()) {
  i.remove();

代码示例来源:origin: opensourceBIM/BIMserver

Iterator<String> fieldNames = objectNode.fieldNames();
while (fieldNames.hasNext()) {
  String fieldName = fieldNames.next();

代码示例来源:origin: opensourceBIM/BIMserver

Iterator<String> fieldNames = jsonObject.fieldNames();
int nrFields = 0;
while (fieldNames.hasNext()) {

代码示例来源:origin: org.openapitools.swagger.parser/swagger-parser-v3

public Set<String> getKeys(ObjectNode node) {
  Set<String> keys = new LinkedHashSet<>();
  if (node == null) {
    return keys;
  }
  Iterator<String> it = node.fieldNames();
  while (it.hasNext()) {
    keys.add(it.next());
  }
  return keys;
}

代码示例来源:origin: io.micronaut/runtime

@Override
public Set<String> names() {
  Iterator<String> fieldNames = objectNode.fieldNames();
  return CollectionUtils.iteratorToSet(fieldNames);
}

代码示例来源:origin: org.apache.taverna.engine/taverna-workflowmodel-extensions

private void setAllMissingFields(ObjectNode config, ObjectNode defaults) {
  for (String fieldName : forEach(defaults.fieldNames()))
    if (! config.has(fieldName) || config.get(fieldName).isNull())
      config.put(fieldName, defaults.get(fieldName));
}

代码示例来源:origin: io.syndesis.server/server-connector-generator

private static Map<String, ArrayProperty> propertyFrom(final String json) {
  try {
    final ObjectNode object = (ObjectNode) MAPPER.readTree(json);
    final String propertyName = object.fieldNames().next();
    final JsonNode node = object.elements().next();
    final ArrayProperty array = MAPPER.readerFor(Property.class).readValue(node);
    return Collections.singletonMap(propertyName, array);
  } catch (final IOException e) {
    throw new AssertionError("Unable to deserialize given parameter", e);
  }
}

代码示例来源:origin: io.syndesis.rest/rest-connector-generator

private static Map<String, ArrayProperty> propertyFrom(final String json) {
  try {
    final ObjectNode object = (ObjectNode) MAPPER.readTree(json);
    final String propertyName = object.fieldNames().next();
    final JsonNode node = object.elements().next();
    final ArrayProperty array = MAPPER.readerFor(Property.class).readValue(node);
    return Collections.singletonMap(propertyName, array);
  } catch (final IOException e) {
    throw new AssertionError("Unable to deserialize given parameter", e);
  }
}

相关文章

微信公众号

最新文章

更多