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

x33g5p2x  于2022-01-21 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(155)

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

JsonNodeFactory.objectNode介绍

[英]Factory method for constructing an empty JSON Object ("struct") node
[中]用于构造空JSON对象(“struct”)节点的工厂方法

代码示例

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

protected ObjectNode createSchemaNode(String type)
{
  ObjectNode schema = JsonNodeFactory.instance.objectNode();
  schema.put("type", type);
  return schema;
}

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

private Response jsonSuccessResponse(Object result, float took) {
    ObjectNode json = JsonNodeFactory.instance.objectNode();
    json.putPOJO("polygons", result);
    // If you replace GraphHopper with your own brand name, this is fine.
    // Still it would be highly appreciated if you mention us in your about page!
    final ObjectNode info = json.putObject("info");
    info.putArray("copyrights")
        .add("GraphHopper")
        .add("OpenStreetMap contributors");
    info.put("took", Math.round(took * 1000));
    return Response.ok(json).build();
  }
}

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

@Override
public void serialize(MultiException e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
  List<Throwable> errors = e.getErrors();
  ObjectNode json = JsonNodeFactory.instance.objectNode();
  json.put("message", getMessage(errors.get(0)));
  ArrayNode errorHintList = json.putArray("hints");
  for (Throwable t : errors) {
    ObjectNode error = errorHintList.addObject();
    error.put("message", getMessage(t));
    error.put("details", t.getClass().getName());
    if (t instanceof GHException) {
      ((GHException) t).getDetails().forEach(error::putPOJO);
    }
  }
  jsonGenerator.writeObject(json);
}

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

/**
 * Get the default schema node.
 *
 * @return The default schema node.
 */
public static JsonNode getDefaultSchemaNode()
{
  ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
  objectNode.put("type", "any");
  // "required" is false by default, no need to include
  //objectNode.put("required", false);
  return objectNode;
}

代码示例来源:origin: java-json-tools/json-schema-validator

@Override
  public JsonNode digest(final JsonNode schema)
  {
    final ObjectNode ret = FACTORY.objectNode();
    ret.put(keyword, schema.get(keyword));
    return ret;
  }
}

代码示例来源:origin: stackoverflow.com

JsonNodeFactory nodeFactory = new JsonNodeFactory();

ObjectNode node = nodeFactory.objectNode();

ObjectNode child = nodeFactory.objectNode(); // the child

child.put("message", "test");

// etc etc

// and then:

node.put("notification", child);

代码示例来源:origin: spring-io/initializr

protected ObjectNode link(String appUrl, Type type) {
  ObjectNode result = nodeFactory.objectNode();
  result.put("href", generateTemplatedUri(appUrl, type));
  result.put("templated", true);
  return result;
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String groupName( IMetaStoreElementType elementType ) {
 ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
 objectNode.put( "_", "Embedded MetaStore Elements" );
 objectNode.put( "namespace", Preconditions.checkNotNull( elementType.getNamespace() ) );
 objectNode.put( "type", Preconditions.checkNotNull( elementType.getId() ) );
 return objectNode.toString();
}

代码示例来源:origin: java-json-tools/json-schema-validator

@Override
  public JsonNode digest(final JsonNode schema)
  {
    // TODO: return an array directly (same for "required" in v4)
    final ObjectNode ret = FACTORY.objectNode();
    final ArrayNode required = FACTORY.arrayNode();
    ret.put("required", required);

    final JsonNode node = schema.get(keyword);
    final List<String> list = Lists.newArrayList(node.fieldNames());

    Collections.sort(list);

    for (final String field: list)
      if (node.get(field).path("required").asBoolean(false))
        required.add(field);

    return ret;
  }
}

代码示例来源:origin: spring-io/initializr

protected ObjectNode mapType(Type type) {
  ObjectNode result = mapValue(type);
  result.put("action", type.getAction());
  ObjectNode tags = nodeFactory.objectNode();
  type.getTags().forEach(tags::put);
  result.set("tags", tags);
  return result;
}

代码示例来源:origin: java-json-tools/json-schema-validator

@Override
protected JsonNode generateSchema()
{
  final ObjectNode value = FACTORY.objectNode();
  value.put("a", sub1);
  value.put("b", sub2);
  final ObjectNode ret = FACTORY.objectNode();
  ret.put(keyword, value);
  return ret;
}

代码示例来源:origin: spring-io/initializr

protected void type(ObjectNode parent, TypeCapability capability) {
  ObjectNode type = nodeFactory.objectNode();
  type.put("type", "action");
  Type defaultType = capability.getDefault();
  if (defaultType != null) {
    type.put("default", defaultType.getId());
  }
  ArrayNode values = nodeFactory.arrayNode();
  values.addAll(capability.getContent().stream().map(this::mapType)
      .collect(Collectors.toList()));
  type.set("values", values);
  parent.set("type", type);
}

代码示例来源:origin: spring-io/initializr

private static JsonNode mapRepository(Repository repo) {
  ObjectNode node = nodeFactory.objectNode();
  node.put("name", repo.getName())
      .put("url", (repo.getUrl() != null) ? repo.getUrl().toString() : null)
      .put("snapshotEnabled", repo.isSnapshotsEnabled());
  return node;
}

代码示例来源:origin: java-json-tools/json-schema-validator

public SchemaDigesterTest()
{
  schema = FACTORY.objectNode();
  schema.put(K1, K1);
  schema.put(K2, K2);
}

代码示例来源:origin: spring-io/initializr

private ObjectNode dependenciesLink(String appUrl) {
  String uri = (appUrl != null) ? appUrl + "/dependencies" : "/dependencies";
  UriTemplate uriTemplate = new UriTemplate(uri, this.dependenciesVariables);
  ObjectNode result = nodeFactory().objectNode();
  result.put("href", uriTemplate.toString());
  result.put("templated", true);
  return result;
}

代码示例来源:origin: spring-io/initializr

protected void text(ObjectNode parent, TextCapability capability) {
  ObjectNode text = nodeFactory.objectNode();
  text.put("type", capability.getType().getName());
  String defaultValue = capability.getContent();
  if (StringUtils.hasText(defaultValue)) {
    text.put("default", defaultValue);
  }
  parent.set(capability.getId(), text);
}

代码示例来源:origin: java-json-tools/json-schema-validator

@Override
protected JsonNode generateInstance()
{
  final ObjectNode ret = FACTORY.objectNode();
  ret.put("a", "a");
  ret.put("b", "b");
  return ret;
}

代码示例来源:origin: spring-io/initializr

protected void dependencies(ObjectNode parent, DependenciesCapability capability) {
  ObjectNode dependencies = nodeFactory.objectNode();
  dependencies.put("type", capability.getType().getName());
  ArrayNode values = nodeFactory.arrayNode();
  values.addAll(capability.getContent().stream().map(this::mapDependencyGroup)
      .collect(Collectors.toList()));
  dependencies.set("values", values);
  parent.set(capability.getId(), dependencies);
}

代码示例来源:origin: spring-io/initializr

protected ObjectNode mapValue(MetadataElement value) {
  ObjectNode result = nodeFactory.objectNode();
  result.put("id", value.getId());
  result.put("name", value.getName());
  if ((value instanceof Describable)
      && ((Describable) value).getDescription() != null) {
    result.put("description", ((Describable) value).getDescription());
  }
  return result;
}

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

private ObjectNode readSchema(URL schemaUrl) {
  switch (ruleFactory.getGenerationConfig().getSourceType()) {
    case JSONSCHEMA:
    case YAMLSCHEMA:
      ObjectNode schemaNode = NODE_FACTORY.objectNode();
      schemaNode.put("$ref", schemaUrl.toString());
      return schemaNode;
    case JSON:
    case YAML:
      return schemaGenerator.schemaFromExample(schemaUrl);
    default:
      throw new IllegalArgumentException("Unrecognised source type: " + ruleFactory.getGenerationConfig().getSourceType());
  }
}

相关文章