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

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

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

ArrayNode.addArray介绍

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

代码示例

代码示例来源:origin: Silverpeas/Silverpeas-Core

public JSONArray addJSONArray(Function<JSONArray, JSONArray> arrayBuilder) {
 ArrayNode node = jsonArray.addArray();
 arrayBuilder.apply(new JSONArray(node));
 return this;
}

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

private JsonNode array(JsonNode node) {
  if (node instanceof ObjectNode) {
    return ((ObjectNode) node).putArray(currentFieldName);
  } else if (node instanceof ArrayNode) {
    return ((ArrayNode) node).addArray();
  } else {
    return JsonNodeFactory.instance.arrayNode();
  }
}

代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-commons

@SuppressWarnings({"unchecked", "rawtypes"})
private <T> void internalSetCollection(String propertyName, Collection<T> collection, ArrayNode targetArray) {
  for (T childValue : collection) {
    if (childValue == null) {
      // Sets null.
      targetArray.addNull();
    } else if (childValue instanceof Collection) {
      // When T is also a Collection, use recursion.
      ArrayNode childArray = targetArray.addArray();
      this.internalSetCollection(propertyName, (Collection) childValue, childArray);
    } else if (childValue instanceof JsonNode) {
      targetArray.add((JsonNode) childValue);
    } else if (childValue instanceof JsonSerializable) {
      // JsonSerializable
      JsonSerializable castedValue = (JsonSerializable) childValue;
      castedValue.populatePropertyBag();
      targetArray.add(castedValue.propertyBag != null ? castedValue.propertyBag : this.getMapper().createObjectNode());
    } else {
      // POJO, JSONObject, Number (includes Int, Float, Double etc),
      // Boolean, and String.
      targetArray.add(this.getMapper().valueToTree(childValue));
    }
  }
}

代码示例来源:origin: io.atlasmap/atlas-json-core

arrayChild = ((ObjectNode)parentNode).putArray(cleanedSegment);
} else if (parentNode instanceof ArrayNode) {
  arrayChild = ((ArrayNode)parentNode).addArray();
} else {
  throw new AtlasException(String.format("Unknown JsonNode type '%s' for segment '%s'",

代码示例来源:origin: io.atlasmap/atlas-json-core

arrayChild = ((ObjectNode)parentNode).putArray(cleanedSegment);
} else if (parentNode instanceof ArrayNode) {
  arrayChild = ((ArrayNode)parentNode).addArray();
} else {
  throw new AtlasException(String.format("Unknown JsonNode type '%s' for segment '%s'",

代码示例来源:origin: org.n52.sensorweb.sos/admin-controller

@ResponseBody
@RequestMapping(value = ControllerConstants.Paths.ADMIN_DATABASE_EXECUTE, method = RequestMethod.POST)
public String processQuery(@RequestBody String querySQL) {
  try {
    if (this.generalQueryDAO.isPresent()) {
      String q = URLDecoder.decode(querySQL, "UTF-8");
      LOG.info("Query: {}", q);
      GeneralQueryDAO.QueryResult rs = this.generalQueryDAO.get().query(q);
      ObjectNode j = Json.nodeFactory().objectNode();
      if (rs.getMessage() != null) {
        j.put(rs.isError() ? "error" : "message", rs.getMessage());
        return Json.print(j);
      }
      j.putArray(ROWS).addAll(Json.toJSON(rs.getColumnNames()));
      ArrayNode names = j.putArray(NAMES);
      for (GeneralQueryDAO.Row row : rs.getRows()) {
        names.addArray().addAll(Json.toJSON(row.getValues()));
      }
      return Json.print(j);
    }
    return "No general query dao available!";
  } catch (UnsupportedEncodingException ex) {
    LOG.error("Could not decode String", ex);
    return "Could not decode String: " + ex.getMessage();
  } catch (SQLException | IOException ex) {
    LOG.error("Query unsuccesfull.", ex);
    return "Query unsuccesful. Cause: " + ex.getMessage();
  }
}

代码示例来源:origin: 52North/SOS

@ResponseBody
@RequestMapping(value = ControllerConstants.Paths.ADMIN_DATABASE_EXECUTE, method = RequestMethod.POST)
public String processQuery(@RequestBody String querySQL) {
  try {
    if (this.generalQueryDAO.isPresent()) {
      String q = URLDecoder.decode(querySQL, "UTF-8");
      LOG.info("Query: {}", q);
      GeneralQueryDAO.QueryResult rs = this.generalQueryDAO.get().query(q);
      ObjectNode j = Json.nodeFactory().objectNode();
      if (rs.getMessage() != null) {
        j.put(rs.isError() ? "error" : "message", rs.getMessage());
        return Json.print(j);
      }
      j.putArray(ROWS).addAll(Json.toJSON(rs.getColumnNames()));
      ArrayNode names = j.putArray(NAMES);
      for (GeneralQueryDAO.Row row : rs.getRows()) {
        names.addArray().addAll(Json.toJSON(row.getValues()));
      }
      return Json.print(j);
    }
    return "No general query dao available!";
  } catch (UnsupportedEncodingException ex) {
    LOG.error("Could not decode String", ex);
    return "Could not decode String: " + ex.getMessage();
  } catch (SQLException | IOException ex) {
    LOG.error("Query unsuccesfull.", ex);
    return "Query unsuccesful. Cause: " + ex.getMessage();
  }
}

代码示例来源:origin: us.ihmc/ihmc-pub-sub-serializers-extra

ArrayNode element = child.addArray();
if(arr[i] instanceof boolean[])
  write_array((boolean[])arr[i], element);

代码示例来源:origin: us.ihmc/IHMCPubSubSerializersExtra

ArrayNode element = child.addArray();
if(arr[i] instanceof boolean[])
  write_array((boolean[])arr[i], element);

代码示例来源:origin: org.n52.sensorweb.sos/coding-json

private JsonNode encodeSweDataArrayValue(Value<?> value) throws OwsExceptionReport {
  SweDataArrayValue sweDataArrayValue = (SweDataArrayValue) value;
  ObjectNode result = nodeFactory().objectNode();
  ArrayNode jfields = result.putArray(JSONConstants.FIELDS);
  ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
  List<SweField> fields = ((SweDataRecord) sweDataArrayValue.getValue().getElementType()).getFields();
  List<List<String>> values = sweDataArrayValue.getValue().getValues();
  TokenConverter[] conv = new TokenConverter[fields.size()];
  int i = 0;
  for (SweField field : fields) {
    try {
      conv[i++] = TokenConverter.forField(field);
    } catch (IllegalArgumentException e) {
      throw new UnsupportedEncoderInputException(this, field);
    }
    jfields.add(encodeObjectToJson(field));
  }
  for (List<String> block : values) {
    ArrayNode jblock = jvalues.addArray();
    i = 0;
    for (String token : block) {
      jblock.add(conv[i++].convert(token));
    }
  }
  return result;
}

代码示例来源:origin: org.n52.arctic-sea/svalbard-json

private JsonNode encodeSweDataArrayValue(Value<?> value)
    throws EncodingException {
  SweDataArrayValue sweDataArrayValue = (SweDataArrayValue) value;
  ObjectNode result = nodeFactory().objectNode();
  ArrayNode jfields = result.putArray(JSONConstants.FIELDS);
  ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
  List<SweField> fields = ((SweDataRecord) sweDataArrayValue.getValue().getElementType()).getFields();
  List<List<String>> values = sweDataArrayValue.getValue().getValues();
  TokenConverter[] conv = new TokenConverter[fields.size()];
  int i = 0;
  for (SweField field : fields) {
    try {
      conv[i++] = TokenConverter.forField(field);
    } catch (IllegalArgumentException e) {
      throw new UnsupportedEncoderInputException(this, field);
    }
    jfields.add(encodeObjectToJson(field));
  }
  for (List<String> block : values) {
    ArrayNode jblock = jvalues.addArray();
    i = 0;
    for (String token : block) {
      jblock.add(conv[i++].convert(token));
    }
  }
  return result;
}

代码示例来源:origin: org.n52.arctic-sea/svalbard-json

private JsonNode encodeTVPValue(OmObservation o)
    throws EncodingException {
  TVPValue tvpValue = (TVPValue) o.getValue().getValue();
  ObjectNode result = nodeFactory().objectNode();
  List<TimeValuePair> values = tvpValue.getValue();
  if (values != null && !values.isEmpty()) {
    String obsProp = o.getObservationConstellation().getObservableProperty().getIdentifier();
    SweTime timeDef = new SweTime();
    timeDef.setDefinition(OmConstants.PHENOMENON_TIME);
    timeDef.setUom(OmConstants.PHEN_UOM_ISO8601);
    SweField timeField = new SweField(OmConstants.PHENOMENON_TIME_NAME, timeDef);
    SweField valueField = getFieldForValue(obsProp, values.get(0).getValue());
    result.putArray(JSONConstants.FIELDS).add(encodeObjectToJson(timeField))
        .add(encodeObjectToJson(valueField));
    ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
    for (TimeValuePair tvp : values) {
      if (tvp != null && tvp.getValue() != null && tvp.getValue().isSetValue()) {
        jvalues.addArray().add(encodeObjectToJson(tvp.getTime())).add(getTokenForValue(tvp.getValue()));
      }
    }
  }
  return result;
}

代码示例来源:origin: org.n52.sensorweb.sos/coding-json

private JsonNode encodeTVPValue(OmObservation o) throws OwsExceptionReport {
  TVPValue tvpValue = (TVPValue) o.getValue().getValue();
  ObjectNode result = nodeFactory().objectNode();
  List<TimeValuePair> values = tvpValue.getValue();
  if (values != null && !values.isEmpty()) {
    String obsProp = o.getObservationConstellation().getObservableProperty().getIdentifier();
    SweTime timeDef = new SweTime();
    timeDef.setDefinition(OmConstants.PHENOMENON_TIME);
    timeDef.setUom(OmConstants.PHEN_UOM_ISO8601);
    SweField timeField = new SweField(OmConstants.PHENOMENON_TIME_NAME, timeDef);
    SweField valueField = getFieldForValue(obsProp, values.get(0).getValue());
    result.putArray(JSONConstants.FIELDS).add(encodeObjectToJson(timeField))
        .add(encodeObjectToJson(valueField));
    ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
    for (TimeValuePair tvp : values) {
      if (tvp != null && tvp.getValue() != null && tvp.getValue().isSetValue()) {
        jvalues.addArray().add(encodeObjectToJson(tvp.getTime())).add(getTokenForValue(tvp.getValue()));
      }
    }
  }
  return result;
}

代码示例来源:origin: com.redhat.lightblue/lightblue-core-util

return arr.addArray();
} else {
  return arr.addObject();

代码示例来源:origin: com.redhat.lightblue/util

return arr.addArray();
} else {
  return arr.addObject();

代码示例来源:origin: lightblue-platform/lightblue-core

return arr.addArray();
} else {
  return arr.addObject();

相关文章