org.codehaus.jackson.node.ObjectNode.get()方法的使用及代码示例

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

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

ObjectNode.get介绍

[英]Method to use for accessing all fields (with both names and values) of this JSON Object.
[中]方法用于访问此JSON对象的所有字段(包括名称和值)。

代码示例

代码示例来源:origin: apache/incubator-gobblin

private List<String> getDeltaFieldNamesForNewSchema(Schema originalSchema) {
 List<String> deltaFields = new ArrayList<>();
 for (Field field : originalSchema.getFields()) {
  String deltaAttributeField = field.getJsonProp(this.attributeField).getValueAsText();
  ObjectNode objectNode = getDeltaPropValue(deltaAttributeField);
  if (objectNode == null || objectNode.get(this.deltaPropName) == null) {
   continue;
  }
  if (Boolean.parseBoolean(objectNode.get(this.deltaPropName).toString())) {
   deltaFields.add(field.name());
  }
 }
 log.info("Will use delta fields: " + deltaFields);
 return deltaFields;
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override
public List<String> getNodeKeys() {
  LinkedList<String> out = new LinkedList<String>();
  for (Iterator<String> i = node.getFieldNames(); i.hasNext();) {
    String name = i.next();
    JsonNode child = node.get(name);
    if (child.isArray() || child.isObject())
      out.add(name);
  }
  return out;
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

@Override
public boolean equals(Object o)
{
  if (o == this) return true;
  if (o == null) return false;
  if (o.getClass() != getClass()) {
    return false;
  }
  ObjectNode other = (ObjectNode) o;
  if (other.size() != size()) {
    return false;
  }
  if (_children != null) {
    for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
      String key = en.getKey();
      JsonNode value = en.getValue();
      JsonNode otherValue = other.get(key);
      if (otherValue == null || !otherValue.equals(value)) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override
public List<String> getPropertyKeys() {
  LinkedList<String> out = new LinkedList<String>();
  for (Iterator<String> i = node.getFieldNames(); i.hasNext();) {
    String name = i.next();
    JsonNode child = node.get(name);
    if (!child.isArray() && !child.isObject())
      out.add(name);
  }
  return out;
}

代码示例来源:origin: kaaproject/kaa

private List<FileData> recursiveShallowExport(List<FileData> files, CTLSchemaDto parent) throws
     Exception {
  files.add(this.shallowExport(parent));
  ObjectNode object = new ObjectMapper().readValue(parent.getBody(), ObjectNode.class);
  ArrayNode dependencies = (ArrayNode) object.get(DEPENDENCIES);
  if (dependencies != null) {
   for (JsonNode node : dependencies) {
    ObjectNode dependency = (ObjectNode) node;
    String fqn = dependency.get(FQN).getTextValue();
    Integer version = dependency.get(VERSION).getIntValue();
    CTLSchemaDto child = this.findAnyCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(
        fqn, version, parent.getMetaInfo().getTenantId(),
        parent.getMetaInfo().getApplicationId());
    Validate.notNull(child, MessageFormat.format("The dependency [{0}] was not found!", fqn));
    this.recursiveShallowExport(files, child);
   }
  }
  return files;
 }
}

代码示例来源:origin: kaaproject/kaa

if (!object.has(TYPE) || !object.get(TYPE).isTextual()
  || !object.get(TYPE).getTextValue().equals("record")) {
 throw new IllegalArgumentException("The data provided is not a record!");
if (!object.has(NAMESPACE) || !object.get(NAMESPACE).isTextual()) {
 throw new IllegalArgumentException("No namespace specified!");
} else if (!object.has(NAME) || !object.get(NAME).isTextual()) {
 throw new IllegalArgumentException("No name specified!");
} else {
 fqn = object.get(NAMESPACE).getTextValue() + "." + object.get(NAME).getTextValue();
schema.setMetaInfo(metaInfo);
if (!object.has(VERSION) || !object.get(VERSION).isInt()) {
 object.put(VERSION, 1);
schema.setVersion(object.get(VERSION).asInt());
if (!object.has(DEPENDENCIES)) {
 schema.setDependencySet(dependencies);
} else if (!object.get(DEPENDENCIES).isArray()) {
 throw new IllegalArgumentException("Illegal dependencies format!");
} else {
 for (JsonNode child : object.get(DEPENDENCIES)) {
  if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual()
    || !child.has(VERSION) || !child.get(VERSION).isInt()) {

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
public boolean equals(Object o)
{
  if (o == this) return true;
  if (o == null) return false;
  if (o.getClass() != getClass()) {
    return false;
  }
  ObjectNode other = (ObjectNode) o;
  if (other.size() != size()) {
    return false;
  }
  if (_children != null) {
    for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
      String key = en.getKey();
      JsonNode value = en.getValue();
      JsonNode otherValue = other.get(key);
      if (otherValue == null || !otherValue.equals(value)) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@SuppressWarnings("deprecation")
@Override
public Object getProperty(String name) {
  JsonNode child = node.get(name);
  if (child==null) return null;
  return child.getValueAsText();
}

代码示例来源:origin: sirensolutions/siren

@Override
public ObjectNode toJson() {
 ObjectNode obj = super.toJson();
 if (this.hasAttribute) {
  ObjectNode node = (ObjectNode) obj.get(NodePropertyParser.NODE_PROPERTY);
  node.put(AttributePropertyParser.ATTRIBUTE_PROPERTY, attribute);
 }
 return obj;
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override
public boolean isProperty(String name) {
  JsonNode child = node.get(name);
  return (child!=null && !child.isArray() && !child.isObject());
}

代码示例来源:origin: org.jboss.seam.social/seam-social-facebook

private String determinePostType(ObjectNode node) {
  if (node.has("type")) {
    try {
      String type = node.get("type").getTextValue();
      PostType.valueOf(type.toUpperCase());
      return type;
    } catch (IllegalArgumentException e) {
      return "post";
    }
  }
  return "post";
}

代码示例来源:origin: com.googlecode.etl-unit/json-validator

private String readString(ObjectNode node, String property) throws JsonSchemaValidationException {
  JsonNode reqNode = node.get(property);
  if (reqNode == null)
  {
    return null;
  }
  if (!reqNode.isTextual())
  {
    throw new JsonSchemaValidationException(property + " property must be a string", "", reqNode, null);
  }
  return reqNode.asText();
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override
public IConfig getNode(String name) {
  JsonNode child = node.get(name);
  if (child == null) return null;
  if (child.isObject() || child.isArray())
    return new JsonConfig(name, this, child);
  return null;
}

代码示例来源:origin: com.ngdata/hbase-indexer-model

private IndexerDefinitionBuilder getDefinitionFromNode(ObjectNode baseNode, String name) {
  JsonNode node = baseNode.get(name);
  if (node == null || node.isNull() || !node.isObject()) {
   throw new JsonFormatException("Unable to find object field: " + name);
  }
  return IndexerDefinitionJsonSerDeser.INSTANCE.fromJson((ObjectNode)node);
 }
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override
public void setProperty(String name, Object value) {
  JsonNode child = node.get(name);
  if (child==null || !child.isArray() && !child.isObject())
    getNode().put(name,MCast.objectToString(value));
}

代码示例来源:origin: apache/samza

/**
 * Given a {@link ContainerModel} JSON with an unknown field, deserialization should properly ignore it.
 */
@Test
public void testDeserializeUnknownTaskModelField() throws IOException {
 ObjectNode jobModelJson = buildJobModelJson();
 ObjectNode taskModelJson = (ObjectNode) jobModelJson.get("containers").get("1").get("tasks").get("test");
 taskModelJson.put("unknown_task_model_key", "unknown_task_model_value");
 assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson));
}

代码示例来源:origin: apache/samza

/**
 * Given a {@link ContainerModel} JSON with neither a processor-id nor a container-id, deserialization should fail.
 */
@Test(expected = SamzaException.class)
public void testDeserializeContainerModelMissingProcessorIdAndContainerId() throws IOException {
 ObjectNode jobModelJson = buildJobModelJson();
 ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1");
 containerModelJson.remove("processor-id");
 deserializeFromObjectNode(jobModelJson);
}

代码示例来源:origin: apache/samza

/**
 * Given a {@link ContainerModel} JSON with a processor-id and a container-id, deserialization should properly ignore
 * the container-id.
 */
@Test
public void testDeserializeContainerIdAndProcessorId() throws IOException {
 ObjectNode jobModelJson = buildJobModelJson();
 ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1");
 containerModelJson.put("container-id", 123);
 assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson));
}

代码示例来源:origin: apache/samza

/**
 * Given a {@link ContainerModel} JSON with an unknown field, deserialization should properly ignore it.
 */
@Test
public void testDeserializeUnknownContainerModelField() throws IOException {
 ObjectNode jobModelJson = buildJobModelJson();
 ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1");
 containerModelJson.put("unknown_container_model_key", "unknown_container_model_value");
 assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson));
}

代码示例来源:origin: apache/samza

/**
 * Given a {@link ContainerModel} JSON without a processor-id but with a container-id, deserialization should use the
 * container-id to calculate the processor-id.
 */
@Test
public void testDeserializeContainerModelOnlyContainerId() throws IOException {
 ObjectNode jobModelJson = buildJobModelJson();
 ObjectNode containerModelJson = (ObjectNode) jobModelJson.get("containers").get("1");
 containerModelJson.remove("processor-id");
 containerModelJson.put("container-id", 1);
 assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson));
}

相关文章