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

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

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

ObjectNode.putArray介绍

[英]Method that will construct an ArrayNode and add it as a field of this ObjectNode, replacing old value, if any.
[中]方法,该方法将构造ArrayNode并将其添加为此ObjectNode的字段,替换旧值(如果有)。

代码示例

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

@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
  // [JACKSON-684]: serialize as index?
  if (provider.isEnabled(SerializationConfig.Feature.WRITE_ENUMS_USING_INDEX)) {
    return createSchemaNode("integer", true);
  }
  ObjectNode objectNode = createSchemaNode("string", true);
  if (typeHint != null) {
    JavaType type = provider.constructType(typeHint);
    if (type.isEnumType()) {
      ArrayNode enumNode = objectNode.putArray("enum");
      for (SerializedString value : _values.values()) {
        enumNode.add(value.getValue());
      }
    }
  }
  return objectNode;
}

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

@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
  // [JACKSON-684]: serialize as index?
  if (provider.isEnabled(SerializationConfig.Feature.WRITE_ENUMS_USING_INDEX)) {
    return createSchemaNode("integer", true);
  }
  ObjectNode objectNode = createSchemaNode("string", true);
  if (typeHint != null) {
    JavaType type = provider.constructType(typeHint);
    if (type.isEnumType()) {
      ArrayNode enumNode = objectNode.putArray("enum");
      for (SerializedString value : _values.values()) {
        enumNode.add(value.getValue());
      }
    }
  }
  return objectNode;
}

代码示例来源:origin: net.sf.sido/sido

@Override
protected void createArray(JsonNode e, String pName, List<JsonNode> elements) {
  ArrayNode array = ((ObjectNode) e).putArray(pName);
  for (JsonNode objectNode : elements) {
    array.add(objectNode);
  }
}

代码示例来源:origin: NGDATA/hbase-indexer

private void setStringArrayProperty(ObjectNode node, String property, String[] strings) {
  if (strings != null) {
    ArrayNode arrayNode = node.putArray(property);
    for (String string : strings) {
      arrayNode.add(string);
    }
    node.put(property, arrayNode);
  }
}

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

private void setStringArrayProperty(ObjectNode node, String property, String[] strings) {
  if (strings != null) {
    ArrayNode arrayNode = node.putArray(property);
    for (String string : strings) {
      arrayNode.add(string);
    }
    node.put(property, arrayNode);
  }
}

代码示例来源:origin: NGDATA/lilyproject

public byte[] toBytes() {
  ObjectNode node = JsonNodeFactory.instance.objectNode();
  node.put("default", defaultAccess);
  ArrayNode limitsNode = node.putArray("limits");
  for (Entry<String, Long> limit : limits.entrySet()) {
    ObjectNode limitNode = limitsNode.addObject();
    limitNode.put("store", limit.getKey());
    limitNode.put("limit", limit.getValue());
  }
  return JsonFormat.serializeAsBytesSoft(node, "BlobStoreAccessConfig");
}

代码示例来源:origin: eBay/YiDB

@SuppressWarnings("rawtypes")
private void addJsonNode(ObjectNode jsonNode, String key, Object value) {
  if (value instanceof Integer) {
    jsonNode.put(key, (Integer) value);
  } else if (value instanceof String) {
    jsonNode.put(key, (String) value);
  } else if (value instanceof Long) {
    jsonNode.put(key, (Long) value);
  } else if (value instanceof List) {
    ArrayNode arrayNode = jsonNode.putArray(key);
    addListNode(arrayNode, (List) value);
  } else {
    jsonNode.put(key, String.valueOf(value));
  }
}

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

@GET
@Path("{instanceName}/healthreports")
public Response getHealthReportsOnInstance(@PathParam("clusterId") String clusterId,
  @PathParam("instanceName") String instanceName) throws IOException {
 HelixDataAccessor accessor = getDataAccssor(clusterId);
 ObjectNode root = JsonNodeFactory.instance.objectNode();
 root.put(Properties.id.name(), instanceName);
 ArrayNode healthReportsNode = root.putArray(InstanceProperties.healthreports.name());
 List<String> healthReports =
   accessor.getChildNames(accessor.keyBuilder().healthReports(instanceName));
 if (healthReports != null && healthReports.size() > 0) {
  healthReportsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(healthReports));
 }
 return JSONRepresentation(root);
}

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

@GET
@Path("{instanceName}/resources")
public Response getResourcesOnInstance(@PathParam("clusterId") String clusterId,
  @PathParam("instanceName") String instanceName) throws IOException {
 HelixDataAccessor accessor = getDataAccssor(clusterId);
 ObjectNode root = JsonNodeFactory.instance.objectNode();
 root.put(Properties.id.name(), instanceName);
 ArrayNode resourcesNode = root.putArray(InstanceProperties.resources.name());
 List<String> sessionIds = accessor.getChildNames(accessor.keyBuilder().sessions(instanceName));
 if (sessionIds == null || sessionIds.size() == 0) {
  return null;
 }
 // Only get resource list from current session id
 String currentSessionId = sessionIds.get(0);
 List<String> resources =
   accessor.getChildNames(accessor.keyBuilder().currentStates(instanceName, currentSessionId));
 if (resources != null && resources.size() > 0) {
  resourcesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(resources));
 }
 return JSONRepresentation(root);
}

代码示例来源:origin: org.codehaus.jackson/com.springsource.org.codehaus.jackson.mapper

@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
  throws JsonMappingException
{
  ObjectNode objectNode = createSchemaNode("string", true);
  if (typeHint != null) {
    JavaType type = TypeFactory.type(typeHint);
    if (type.isEnumType()) {
      ArrayNode enumNode = objectNode.putArray("enum");
      for (String value : _values.values()) {
        enumNode.add(value);
      }
    }
  }
  return objectNode;
}

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

@GET
public Response getJobs(@PathParam("clusterId") String clusterId,
  @PathParam("workflowName") String workflowName) {
 TaskDriver driver = getTaskDriver(clusterId);
 WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflowName);
 ObjectNode root = JsonNodeFactory.instance.objectNode();
 if (workflowConfig == null) {
  return badRequest(String.format("Workflow %s is not found!", workflowName));
 }
 Set<String> jobs = workflowConfig.getJobDag().getAllNodes();
 root.put(Properties.id.name(), JobProperties.Jobs.name());
 ArrayNode jobsNode = root.putArray(JobProperties.Jobs.name());
 if (jobs != null) {
  jobsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(jobs));
 }
 return JSONRepresentation(root);
}

代码示例来源:origin: com.barchart.wrap/barchart-wrap-jackson

@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
  ObjectNode objectNode = createSchemaNode("string", true);
  if (typeHint != null) {
    JavaType type = provider.constructType(typeHint);
    if (type.isEnumType()) {
      ArrayNode enumNode = objectNode.putArray("enum");
      for (SerializedString value : _values.values()) {
        enumNode.add(value.getValue());
      }
    }
  }
  return objectNode;
}

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

private ObjectNode writeSpan(Span span) throws IOException {
  log.trace("wirte {}",span);
  ObjectNode jSpan = mapper.createObjectNode();
  jSpan.put("type", span.getType().name());
  jSpan.put("start", span.getStart());
  jSpan.put("end", span.getEnd());
  for(String key : span.getKeys()){
    List<Value<?>> values = span.getValues(key);
    if(values.size() == 1){
      jSpan.put(key, writeValue(values.get(0)));
    } else {
      ArrayNode jValues = jSpan.putArray(key);
      for(Value<?> value : values){
        jValues.add(writeValue(value));
      }
      jSpan.put(key, jValues);
    }
  }
  log.trace(" ... {}",jSpan);
  return jSpan;
}

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

@GET
public Response getResources(@PathParam("clusterId") String clusterId) {
 ObjectNode root = JsonNodeFactory.instance.objectNode();
 root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId));
 HelixZkClient zkClient = getHelixZkClient();
 ArrayNode idealStatesNode = root.putArray(ResourceProperties.idealStates.name());
 ArrayNode externalViewsNode = root.putArray(ResourceProperties.externalViews.name());
 List<String> idealStates = zkClient.getChildren(PropertyPathBuilder.idealState(clusterId));
 List<String> externalViews = zkClient.getChildren(PropertyPathBuilder.externalView(clusterId));
 if (idealStates != null) {
  idealStatesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(idealStates));
 } else {
  return notFound();
 }
 if (externalViews != null) {
  externalViewsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(externalViews));
 }
 return JSONRepresentation(root);
}

代码示例来源:origin: rdelbru/SIREn

@Override
ObjectNode toJson() {
 final ObjectNode obj = mapper.createObjectNode();
 final ArrayNode bool = obj.putArray(BooleanPropertyParser.BOOLEAN_PROPERTY);
 for (final QueryClause clause : clauses) {
  final ObjectNode e = bool.addObject();
  e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString());
  e.putAll(clause.getQuery().toJson());
 }
 return obj;
}

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

@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
  // [JACKSON-684]: serialize as index?
  if (provider.isEnabled(SerializationConfig.Feature.WRITE_ENUMS_USING_INDEX)) {
    return createSchemaNode("integer", true);
  }
  ObjectNode objectNode = createSchemaNode("string", true);
  if (typeHint != null) {
    JavaType type = provider.constructType(typeHint);
    if (type.isEnumType()) {
      ArrayNode enumNode = objectNode.putArray("enum");
      for (SerializedString value : _values.values()) {
        enumNode.add(value.getValue());
      }
    }
  }
  return objectNode;
}

代码示例来源:origin: NGDATA/lilyproject

@Override
public ObjectNode toJson(RecordFilterList filter, Namespaces namespaces, LRepository repository,
    RecordFilterJsonConverter<RecordFilter> converter)
    throws RepositoryException, InterruptedException {
  ObjectNode node = JsonFormat.OBJECT_MAPPER.createObjectNode();
  if (filter.getOperator() != null) {
    node.put("operator", filter.getOperator().toString());
  }
  if (filter.getFilters() != null) {
    ArrayNode filters = node.putArray("filters");
    for (RecordFilter subFilter : filter.getFilters()) {
      filters.add(converter.toJson(subFilter, namespaces, repository, converter));
    }
  }
  return node;
}

代码示例来源:origin: rdelbru/SIREn

@Override
ObjectNode toJson() {
 final ObjectNode obj = mapper.createObjectNode();
 final ObjectNode node = obj.putObject(NodePropertyParser.NODE_PROPERTY);
 node.put(QueryPropertyParser.QUERY_PROPERTY, booleanExpression);
 if (this.hasLevel()) {
  node.put(LevelPropertyParser.LEVEL_PROPERTY, this.getLevel());
 }
 if (this.hasRange()) {
  final ArrayNode array = node.putArray(RangePropertyParser.RANGE_PROPERTY);
  array.add(this.getLowerBound());
  array.add(this.getUpperBound());
 }
 if (this.hasBoost()) {
  node.put(BoostPropertyParser.BOOST_PROPERTY, this.getBoost());
 }
 return obj;
}

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

@Override
public ObjectNode toJson() {
 final ObjectNode obj = mapper.createObjectNode();
 final ObjectNode node = obj.putObject(NodePropertyParser.NODE_PROPERTY);
 node.put(QueryPropertyParser.QUERY_PROPERTY, booleanExpression);
 if (this.hasLevel()) {
  node.put(LevelPropertyParser.LEVEL_PROPERTY, this.getLevel());
 }
 if (this.hasRange()) {
  final ArrayNode array = node.putArray(RangePropertyParser.RANGE_PROPERTY);
  array.add(this.getLowerBound());
  array.add(this.getUpperBound());
 }
 if (this.hasBoost()) {
  node.put(BoostPropertyParser.BOOST_PROPERTY, this.getBoost());
 }
 return obj;
}

代码示例来源:origin: io.hops/hadoop-mapreduce-client-app

@Private
public JsonNode countersToJSON(Counters counters) {
 ArrayNode nodes = FACTORY.arrayNode();
 if (counters != null) {
  for (CounterGroup counterGroup : counters) {
   ObjectNode groupNode = nodes.addObject();
   groupNode.put("NAME", counterGroup.getName());
   groupNode.put("DISPLAY_NAME", counterGroup.getDisplayName());
   ArrayNode countersNode = groupNode.putArray("COUNTERS");
   for (Counter counter : counterGroup) {
    ObjectNode counterNode = countersNode.addObject();
    counterNode.put("NAME", counter.getName());
    counterNode.put("DISPLAY_NAME", counter.getDisplayName());
    counterNode.put("VALUE", counter.getValue());
   }
  }
 }
 return nodes;
}

相关文章